How to get IP address

I am trying to get the IP address of the PC that will be updating records in database and insert into one of the field of the record. I get need the local LAN IP for now as the application using VB 2500 express with MySQL will be running in a local LAN.

Vincent



Answer this question

How to get IP address

  • Louis Phillipee

    How about something like this There's a lot of information in the System.Net namespace, but this is what I found by scouting around, but there may be an easier way:

    Imports System.Net.NetworkInformation

    Public Class
    Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Handles MyBase.Load
    Dim adapters As
    NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
    Dim adapter As
    NetworkInterface
    For Each adapter In
    adapters
    Debug.WriteLine(adapter.Description)
    Dim adapterProperties As
    IPInterfaceProperties = adapter.GetIPProperties()
    Dim addresses As
    UnicastIPAddressInformationCollection = adapterProperties.UnicastAddresses
    If addresses.Count > 0
    Then
    Dim addr As
    UnicastIPAddressInformation
    For Each addr In
    addresses
    Debug.WriteLine("Address: "
    & addr.Address.ToString())
    Next
    addr
    End
    If
    Next
    adapter
    End
    Sub
    End
    Class



  • smhaig

    Give the below code a try. Just keep in mind that a host machine can be assigned more than one IP address:

    Dim IpEntry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(Environment.MachineName)

    Dim IpAddr As System.Net.IPAddress() = IpEntry.AddressList

    Dim IpAddrIndex As Integer
    For IpAddrIndex = 0 To IpAddr.Length - 1

    Console.WriteLine(IpAddr(IpAddrIndex).ToString)

    Next

     



  • rsedor

    Dim sIPAddress

    sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If sIPAddress="" Then sIPAddress = Request.ServerVariables("REMOTE_ADDR")


  • microuser

    How about the subnet address

  • dan6546546

    Thanks so much. Both the above works for me.
  • How to get IP address