Need to show users public IP in a window form C#

  • Thread starter Thread starter Bikky Kumar Rai
  • Start date Start date
B

Bikky Kumar Rai

Guest
I have a requirement to show user(s) public ip address, in a Window Form.

i tried below line of code but it is not giving me the client ip:

1-

string ipv6 = string.Empty;
var host = Dns.GetHostEntry(GetCurrentLoogedInHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetworkV6)
{
ipv6 = ip.ToString();
}
}
return ipv6;
2-

string ipv4 = string.Empty;
var host = Dns.GetHostEntry(GetCurrentLoogedInHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
ipv4 = ip.ToString();
}
}
return ipv4;
--------------------------------------------------------------------------------------------------------------

Above code is not giving me the result as the Google or website 'whatismyip' showing. PFB snapshot for more details:


Please help me guys, to get the public IP.


Bikky Kumar

1599405.png

Continue reading...
 
Back
Top