Re: [2008] active ip address
I dont think you can find out the "active" ip address because they are all equally "active"... All you can do is retrieve a list of IPs as you are doing (unless anyone else knows of any other way to do it?)
By the way, that 169 address that you are seeing usually means that one of the network cards (physical or virtual) in your PC is set to receive an IP address from DHCP but no DHCP server has assigned it an IP. How exactly do you want to use this code? I mean what are you going to do with this IP address once you get it? If you tell me that then I might be able to suggest a way to do what you want.
Re: [2008] active ip address
Hi Chris
this is part of a user self help application i have written and the ip is just something the user can read out to the tech. sometimes our company vpn doesnt like certain ip ranges.
Phil
Re: [2008] active ip address
Well if you know which subnets or IP ranges you would be looking for then you could always just loop through each IP in the IP collection you have and test to see if it is on the subnet that you are looking for. For example, if your corporate subnet was 192.168.10.X then you could do something like this to find the VPN assigned IP (if thats what you are after):
vb Code:
Dim addrs() As Net.IPAddress = Net.Dns.GetHostAddresses(Net.Dns.GetHostName)
For i As Integer = 0 To addrs.Count - 1
If addrs(i).ToString.StartsWith("192.168.10") Then
MessageBox.Show(addrs(i).ToString)
End If
Next
That help at all?
Re: [2008] active ip address
thanks its given me an idea of how i can do it thanks.
Re: [2008] active ip address
It depends what you mean by "active" IP address. A system can have 1 or more IP addresses on one or more networks/subnets. The interface (network card) used to communication will depend solely on the routing table which governs which interfaces "know" about which networks.
If you execute route print in a windows command prompt you will see the routing table. Here's an example:
Code:
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.10.0.1 10.10.2.100 25
10.10.0.0 255.255.0.0 10.10.2.100 10.10.2.100 25
10.10.2.100 255.255.255.255 127.0.0.1 127.0.0.1 25
10.255.255.255 255.255.255.255 10.10.2.100 10.10.2.100 25
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.101.1.0 255.255.255.0 192.101.1.1 192.101.1.1 30
192.101.1.1 255.255.255.255 127.0.0.1 127.0.0.1 30
192.101.1.255 255.255.255.255 192.101.1.1 192.101.1.1 30
192.168.55.0 255.255.255.0 192.168.55.1 192.168.55.1 20
192.168.55.1 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.55.255 255.255.255.255 192.168.55.1 192.168.55.1 20
192.168.112.0 255.255.255.0 192.168.112.1 192.168.112.1 20
192.168.112.1 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.112.255 255.255.255.255 192.168.112.1 192.168.112.1 20
172.17.0.0 255.255.0.0 192.101.1.5 192.168.101.1 20
Default Gateway: 10.10.0.1
The above example shows a system with many network interfaces / IP addresses. It can be noted from the routing table that any communications made to a node on the network 172.17.0.0 will be sent through through the interface 192.101.1.1 to the gateway (router) 192.101.1.5. However, communications for a node on the network 10.10.0.0 will be sent through the interface 10.10.2.100.
Of most interest is the default gateway; this is the interface used when an IP address does not match any entries in the routing table. This usually includes addresses on an external WAN such as the Internet. It can be observed here that these are sent to the default gateway 10.10.0.1.
So, to find the interface / address that a communication will go through involve using the routing table to determine weather or not the network you wish to communicate with has an entry.