GetHostEntry

K

Kent Briggs

I'm trying to get the IP address of a named computer in my local
network. The problem is, my code below only works when my Axim
(WM_Kent1) is cradled and connected via active sync to my desktop
(Dell4600). Then I can enter Dell4600 into the textbox and it returns
two IP's, one for the ActiveSync connection itself (169.254.2.2) and
another for the regular LAN IP (192.168.1.100). So far, so good. But
when I uncradle the Axim (and confirm my Wi-Fi is connected), it stops
working and fires an exception: No such host is known. But I can ping
the Axim by name (WM_Kent1) from the desktop and it sees it wirelessly.
So the desktop can see the Axim but the Axim can't see the desktop. Why
is that?

Dim entry As IPHostEntry = Nothing
Try
entry = Dns.GetHostEntry(TextBox1.Text)
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Dim n As Integer = entry.AddressList.Length
If n = 0 Then
MsgBox("No IP address found for " & TextBox1.Text)
Exit Sub
End If
Dim i As Integer
Dim ip As String = entry.HostName & vbCr
For i = 0 To n - 1
ip = ip & "IP = " & entry.AddressList(i).ToString & vbCr
Next
MsgBox(ip)
 
K

Kent Briggs

Kent said:
I'm trying to get the IP address of a named computer in my local
network.

After some experimenting I noticed that Dns.GetHostEntry("Dell4600")
does work if I set my Axim Wi-Fi adapter to "Use specific IP address"
and fill in the IP, mask, and gateway in manually. But I use the same
numbers (192.168.1.2, 255.255.255.0, 192.168.1.1) that it uses when the
setting is "Use server-assigned IP address". So why can't GetHostEntry()
find my other computers on my LAN by name when the IP is server-assigned
since the numbers are all the same anyway?
 
P

Paul G. Tobey [eMVP]

DNS isn't one of those three numbers! The DNS server address is probably
not being sent by your DHCP server but may be set statically for the
adapter. So, when you use static addressing, you get the address from the
registry, which is right, and when you use dynamic addressing, you don't get
the DNS server address, so it doesn't work. At least, that's my first
guess...

Paul T.
 
K

Kent Briggs

Paul said:
DNS isn't one of those three numbers! The DNS server address is probably
not being sent by your DHCP server but may be set statically for the
adapter. So, when you use static addressing, you get the address from the
registry, which is right, and when you use dynamic addressing, you don't get
the DNS server address, so it doesn't work. At least, that's my first
guess...

Yeah, there's a separate tab for name servers (DNS, Alt DNS, WINS, Alt
WINS) which are all blank. A blank DNS appears to be the key here
because when I look in my Axim registry here:

HKLM\Comm\ODIM\TIACXWLN1\Parms\TCPIP

I have the following settings when using a server-assign IP:

DhcpDefaultGateway = 192.168.1.1
DhcpIPAddress = 192.168.1.2
DhcpDNS = 24.93.41.125
DefaultGateway = 0.0.0.0
IpAddress = 0.0.0.0
DNS = (blank)

When I use a static IP, the DefaultGateway and IpAddress get filled in
but the DNS stays blank. So the culprit must be the DhcpDNS value. That
24.93.41.125 number is owned by my ISP and is being fed by my LinkSys
router. And of course my ISP's DNS isn't going to know about the PCs on
my internal LAN.

So is this fixable? I need the Axim to be able to see the outside world
and the other PCs in my LAN without having to use a static IP. I tried
just blanking out the DhcpDNS value in the registry but it had no
immediate affect and was reset when the connection was reset, as expected.
 
P

Paul G. Tobey [eMVP]

Work-aroundable, maybe. I'm not sure what method is being used when the DNS
server list is empty. The only real fix I can see is to *have* a DNS server
on your local network that *does* know the name to IP mapping. It's not
clear to me why it works in the blank case, but something undocumented is
happening under the covers, I think.

Paul T.
 
K

Kent Briggs

Paul said:
Work-aroundable, maybe. I'm not sure what method is being used when the DNS
server list is empty. The only real fix I can see is to *have* a DNS server
on your local network that *does* know the name to IP mapping. It's not
clear to me why it works in the blank case, but something undocumented is
happening under the covers, I think.

The problem with that is my particular application will only know the
SSID of the Wi-Fi network and the name of computer on that network to
which it is trying to fetch the IP. It won't know any IPs on the network
in advance except for what the Wi-Fi router is feeding it via DHCP.
 
P

Paul G. Tobey [eMVP]

The WiFi router should be able to be configured with the DNS server it
should pass to an DHCP clients it has. Alternatively, you should be able to
turn off DHCP on the WiFi router and just have it route DHCP requests to the
wired network it connects with, where you'd have a DHCP server on a desktop
or server machine running. That would *certainly* be able to be configured
with the right DNS server address and the server itself.

Paul T.
 
K

Kent Briggs

Paul said:
The WiFi router should be able to be configured with the DNS server it
should pass to an DHCP clients it has. Alternatively, you should be able to
turn off DHCP on the WiFi router and just have it route DHCP requests to the
wired network it connects with, where you'd have a DHCP server on a desktop
or server machine running. That would *certainly* be able to be configured
with the right DNS server address and the server itself.

Unfortunately in my particular scenario, the Wi-Fi router (which is also
the internet gateway) may be owned by a third party where configuration
changes are not possible.
 
P

Paul G. Tobey [eMVP]

Then you'll have to resolve names by some means other than real DNS. I
don't know enough about .NET CF to really tell you what to try; you'll have
to browse the class library.

Paul T.
 

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