locked
IP Address from Client RRS feed

  • Question

  • I am sure this is a simple request, but how do you retreive the IP Address from clients running the application? 

    Trying to retrieve the information and log it to the database so I can see where users are signing into the application from within the LAN.

    I am using VB.NET 2005 and SQL 2005.

    Thanks in advance for any assistance.

     

     

     

    Monday, December 18, 2006 4:58 AM

Answers

  • to get the local IP Address you can do this:

    Dim theIPAddresses() as System.Net.IPAddress = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())

     

    you will get a collection of IP Address on the local computer, since they could have multiple IP's due to say a loopback adapter being installed or multiple network cards etc...

    then you need to iterate:

     

    for each currentIP as System.Net.IPAddress in theIPAddresses

       'insert currentIP into database but for demo, lets show it to the user onscreen:

       MessageBox.Show(currentIP.ToString())

    next

     

     

    Monday, December 18, 2006 11:40 AM

All replies

  • to get the local IP Address you can do this:

    Dim theIPAddresses() as System.Net.IPAddress = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())

     

    you will get a collection of IP Address on the local computer, since they could have multiple IP's due to say a loopback adapter being installed or multiple network cards etc...

    then you need to iterate:

     

    for each currentIP as System.Net.IPAddress in theIPAddresses

       'insert currentIP into database but for demo, lets show it to the user onscreen:

       MessageBox.Show(currentIP.ToString())

    next

     

     

    Monday, December 18, 2006 11:40 AM
  • Thanks for the example, How do I determine which adapter is the one being used to connect to the application?

     

    Monday, December 18, 2006 3:46 PM
  • Based on your answers, and the reference in MSDN then it appears that System.Net.Dns.GetHostName() when used on a web server will actually return the name of the web server not the client on which web app is being viewed.  Would you concur?

    Edward R. Joell MCSD MCDBA

    Friday, October 5, 2012 2:07 PM