我设法得到了我的静态IP地址和其他一些mac地址。
使用此代码:
IPAddress[] addr = Dns.GetHostEntry( Dns.GetHostName() ).AddressList;
string dynamicip = addr[addr.Length - 3].ToString();
任何想法如何获得动态公共地址,如网站whatismyip.com上的那个?
答案 0 :(得分:5)
whatismyip.com为此目的设置了api(某种)设置here。你可以用
public static IPAddress GetExternalIP()
{
string url = "http://www.whatismyip.com/automation/n09230945.asp";
WebClient webClient = new WebClient();
string response = utf8.GetString(webClient .DownloadData(whatIsMyIp));
IPAddress ip = IPAddress.Parse(response);
return ip;
}
答案 1 :(得分:0)
对于IP地址,您可以使用HttpContext.Current.Request.UserHostAddress;
for windows form check How to detect static ip using win app in c#
brgds
答案 2 :(得分:0)