tags:

views:

58

answers:

2

Hai Friends

I am Developing a application in that i am returning the ipaddress for the patricular system and save it in the database.but when check the database it is showing the server ip address but i want get the particular ip address who is running that application.

So far i have used this coding:

  Public Function GetIPAddress() As String
        Dim strHostName As String = System.Net.Dns.GetHostName()
        Dim strHostName1 As String = System.Net.Dns.GetHostName()
        Dim ipHostInfo As System.Net.IPHostEntry = System.Net.Dns.Resolve(System.Net.Dns.GetHostName())
        Dim ipAddress As System.Net.IPAddress = ipHostInfo.AddressList(0)
        Return ipAddress.ToString()
    End Function
+1  A: 

Keep in mind that a machine may have multiple IP addresses pointing to it, so this isn't really possible. Well, not in theory anyway - in practice, you may be able to hack something together.

troelskn
+1  A: 

That's undoubtedly because your code is running on the server itself, not the client. Hence, when you ask for the IP address, it faithfully gives it to you.

Any solution running on the server (such as examining the source IP address of the TCP session) has to keep in mind that, with firewalls and network address translation and all the other wonderful features of networking that protect us from the baddies, the address you get may bear little resemblance to the actual IP address of the client machine.

You need to get code running on the client machine that can basically do the same thing. And keep in mind there that a client may have many IP addresses allocated to it.

On my desktop machine alone, I have two physical NICs, each with two addresses and multiple virtual NICs for VPNs and VMWare images. Granted, my desktop box is not your ordinary home PC, but it's not out of the realms of possibility for a box to have two addresses.

And, in fact, a single machine can quite easily change its IP address if on DHCP and it decides to release the lease on its address and get another one.

All in all, the IP address is not a very reliable indicator of which machine is doing things. Perhaps if you step back and give us more details on what you're trying to achieve, we can help further.

paxdiablo
my project is in the server waht should id do
vigna hari karthik
@vigna, any code running on the server is inherently unreliable at getting the client IP address. For example, in our little empire here, we have about a hundred different machines that all present to the outside world as a single NAT'ed IP address (using ports to do the routing). You need to re-architect your application to get code running on the client or live with the possibility that the information won't be reliable. If that's okay, you need to get the source IP from the underlying socket of whatever communication method you're using.
paxdiablo