System.Net.Dns????

B

Brian

Hi.. I don't get it.... this procedure is obsolete.. that is obsolete....
I am trying to rewrite a program i wrote in vb 6 years ago
Dim hostIPAddress As IPAddress = IPAddress.Parse(Me.txtLookupHostIP.Text)

Dim hostinfo As IPHostEntry =
System.Net.Dns.GetHostEntry(hostIPAddress.ToString)



?system.Net.Dns.Resolve(hostIPAddress.ToString)

{System.Net.IPHostEntry}

AddressList: {Length=1}

Aliases: {Length=0}

HostName: "ComputerName.DomainName"



?System.Net.Dns.GetHostEntry(hostIPAddress.ToString)

Run-time exception thrown : System.Net.Sockets.SocketException - No such
host is known

warnings say not to use resolve, but to use GetHostEntry

I am just trying to pass an IP address and get the Host name... either from
the internet or local network.. or pass the host name and get the ip..
 
K

kimiraikkonen

I am just trying to pass an IP address and get the Host name... either from
the internet or local network.. or pass the host name and get the ip..

Using VB 2005, i can get hostname simply by using:
System.Net.Dns.GetHostName.ToString

And getting IP address by passing hostname can be done using:
'-----------------------------------
Imports System.Net.Dns
Imports System.Net

Dim hostname As String
hostname = GetHostName.ToString
For Each ip As IPAddress In _
GetHostEntry(hostname).AddressList
' Return IP address in messagebox
MsgBox(ip.ToString)
Next
'------------------------------

Hope this helps,

Onur Güzel
 
B

Brian

ok, now what about passing an ip address?
MsgBox(GetHostEntry(Me.txtLookupHostIP.Text).HostName)

me.txtLookupHostIP.text = 192.168.1.1 This address is assigned from a dhcp
server on the local network....

and is listed in the dns.. and I get "No such host is known"



I am just trying to pass an IP address and get the Host name... either
from
the internet or local network.. or pass the host name and get the ip..

Using VB 2005, i can get hostname simply by using:
System.Net.Dns.GetHostName.ToString

And getting IP address by passing hostname can be done using:
'-----------------------------------
Imports System.Net.Dns
Imports System.Net

Dim hostname As String
hostname = GetHostName.ToString
For Each ip As IPAddress In _
GetHostEntry(hostname).AddressList
' Return IP address in messagebox
MsgBox(ip.ToString)
Next
'------------------------------

Hope this helps,

Onur Güzel
 
K

kimiraikkonen

ok, now what about passing an ip address?
MsgBox(GetHostEntry(Me.txtLookupHostIP.Text).HostName)

me.txtLookupHostIP.text = 192.168.1.1   This address is assigned froma dhcp
server on the local network....

and is listed in the dns.. and I get "No such host is known"




Using VB 2005, i can get hostname simply by using:
System.Net.Dns.GetHostName.ToString

And getting IP address by passing hostname can be done using:
'-----------------------------------
Imports System.Net.Dns
Imports System.Net

Dim hostname As String
hostname = GetHostName.ToString
For Each ip As IPAddress In _
GetHostEntry(hostname).AddressList
 ' Return IP address in messagebox
MsgBox(ip.ToString)
Next
'------------------------------

Hope this helps,

Onur Güzel

Well, it seems you want to get host name by passing an IP address and
that can be done using:

Imports System.Net.Dns

' Your computer's LAN IP address
' assigned by your router or LAN device
Dim ip As String = "192.168.1.2"
' that returns my hostname
MsgBox(GetHostEntry(ip).HostName.ToString)

Note: You must pay attention to your firewall installed on your
machine, which may prevent you from retrieving info about your IP
address, and may require to set "trusted" rule or similar manually.
Plus make sure, you're passing correct IP address.

Hope this helps,

Onur Güzel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top