获取客户端系统的IP地址 [英] To get Client system ip address
本文介绍了获取客户端系统的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家。
我想要c#代码来获取客户端系统的IP地址。我使用了这段代码
hi experts.
i want c# code for to get client system ip address. i used this code
public string GetIpAddress()
{
string stringIpAddress;
stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (stringIpAddress == null)
{
stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
return "Visitor IP Address is "+stringIpAddress;
}
使用此代码我得到答案为:: 1..我不想要这个。我想要系统ipv4地址。
请帮帮我
在此先感谢....
using this code i get answer as " ::1 ".. i don''t want this.. i want system ipv4 address.
please help me
Thanks in Advance....
推荐答案
你好
使用System.Net;
私人字符串GetIP()
{
string strHostName =;
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress [] addr = ipEntry.AddressList;
返回addr [addr.Length-1] .ToString();
}
谢谢,
Abhimanyu Rawat
Hello
using System.Net;
Private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length-1].ToString();
}
Thanks,
Abhimanyu Rawat
这篇关于获取客户端系统的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文