本文介绍了使用C#获取客户端的真实IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public string Get_real_IP(string Provider)
{
HttpWebRequest SendReq = HttpWebRequest.Create(Provider);
HttpWebResponse GetRes = SendReq.GetResponse();
System.IO.Stream StreamRes = GetRes.GetResponseStream;
StreamReader ResStrmRdr = new StreamReader(ResStream, Encoding.UTF8);
string IP = ResStrmRdr.ReadToEnd;
StreamRes.Close();
GetRes.Close();
return IP;
}
推荐答案
public static string GetIpAddress() // Get IP Address
{
string ip = "";
IPHostEntry ipEntry = Dns.GetHostEntry(GetCompCode());
IPAddress[] addr = ipEntry.AddressList;
ip = addr[2].ToString();
return ip;
}
public static string GetCompCode() // Get Computer Name
{
string strHostName = "";
strHostName = Dns.GetHostName();
return strHostName;
}
string IP = GetIP();
public string GetIP()
{
string Str = "";
Str = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(Str);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length - 1].ToString();
}
这篇关于使用C#获取客户端的真实IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!