use*_*444 0 c# ip dns winforms
我设法获得了我的静态IP地址和其他一些mac地址.
使用此代码:
IPAddress[] addr = Dns.GetHostEntry( Dns.GetHostName() ).AddressList;
string dynamicip = addr[addr.Length - 3].ToString();
Run Code Online (Sandbox Code Playgroud)
任何想法如何获得像网站whatismyip.com上的动态公共地址?
whatismyip.com 在这里为此目的设置了api(某种)设置.您可以使用
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;
}
Run Code Online (Sandbox Code Playgroud)