C# 获取*IP地址

直接上代码:
public
static string getLocalIP() { String direction = ""; string url = "http://checkip.dyndns.org/"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "PROPFIND"; request.ContentType = "application/x-www-form-urlencoded;charset:utf-8"; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream stream = response.GetResponseStream(); using (StreamReader streamReader = new StreamReader(stream, Encoding.UTF8)) { direction = streamReader.ReadToEnd().ToString(); } } //Search for the ip in the html int first = direction.IndexOf("Address: ") + 9; int last = direction.LastIndexOf("</body>"); direction = direction.Substring(first, last - first); return direction; }
原文地址:https://www.cnblogs.com/zhouyuqiu/p/12792827.html