Results 1 to 5 of 5

Thread: How do i auto detect the ip address in vb .net

  1. #1
    Join Date
    Jul 2006
    Posts
    13
    Rep Power
    0

    Smile How do i auto detect the ip address in vb .net

    I am trying to wirte some code to atomatically detect the ip address on the computer it is on. Does any body have any idea what syntax i would used to get this done

  2. #2
    Join Date
    Feb 2006
    Posts
    185
    Rep Power
    0

    Default

    Code:
    Private sub getIP()
    
    Dim address as String
    address = winsock1.LocalIP
    
    End Sub

  3. #3
    girldemsuga Guest

    Default

    Quote Originally Posted by Sutra
    Private sub getIP()

    Dim address as String
    address = winsock1.LocalIP

    End Sub
    The will work but you will have to add "Microsoft Winsock Control" component to you project.

  4. #4
    Join Date
    May 2003
    Posts
    108
    Rep Power
    0

    Default

    Code:
    Imports System.Net
    
    Function getIP() as String
    
            Dim IP As IPHostEntry = New IPHostEntry
    
            'get the IP addresses associated with the host
            IP = Dns.Resolve(Dns.GetHostName)
    
            Dim arrIP() As IPAddress = IP.AddressList
        arrIP(0).ToString)
    
    End Function
    Last edited by Arch_Angel; Jul 26, 2006 at 09:19 AM. Reason: added CODE tags

  5. #5
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    This can also be done in the .Net 2.0 library in the System.Net.NetworkInformation Namespace

    The idea is to get the network card on the computer and then check its properties, namely IP address. Remember that a computer can have more than network card and each are using a different IP address, so this method allows identification of the different IP addresses.

    Code:
    NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
    Use System.Net.NetworkInformation.GetAllNetworkInterfaces()
    to get all
    System.Net.NetworkInformation.NetworkInterface
    then from
    Code:
    adapters[0]; //read how to get the ip stats used
    get the IP address from some property on the card.

    I remember using the same code above vaguely when I used .net 2.0 beta more that a year ago.

    If you are using .net 2.0 now then read up in these classes. I recall this to work nicely but I lost my original snippet.

    I remember someone here did a code that showed this too. It may have been the winsock class or some other class, but it showed up the ip just like the ip in the display of network properties.

    The ip address that is used as a gateway. I am not sure how to get that at this time. You ever noticed a site which gives you your ip address but the address is not correct but you think it is the address of your router or something?
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

Posting Permissions

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