Results 1 to 6 of 6

Thread: [2008] active ip address

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    [2008] active ip address

    Hi All

    I have tried searching but not coming up with what i need.

    Below is the code i am using to get the IP address

    Code:
    Dim addrs() As IPAddress = Dns.GetHostAddresses(Dns.GetHostName)
    
            If addrs.Length > 0 Then
                TxtBxIP.Text = addrs(0).ToString
            End If
    the problem is the first address is appearing as 169. so how can i only display the active IP address? In my case its addrs(1) but i am sharing the application so it might not always be (1)

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    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

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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:
    1. Dim addrs() As Net.IPAddress = Net.Dns.GetHostAddresses(Net.Dns.GetHostName)
    2.  
    3. For i As Integer = 0 To addrs.Count - 1
    4.     If addrs(i).ToString.StartsWith("192.168.10") Then
    5.         MessageBox.Show(addrs(i).ToString)
    6.     End If
    7. Next

    That help at all?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: [2008] active ip address

    thanks its given me an idea of how i can do it thanks.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width