C#获取本机局域网ip和公网ip
来源:互联网 发布:神经网络 凸优化问题 编辑:程序博客网 时间:2024/06/09 23:14
原文地址:http://www.cnblogs.com/slyzly/articles/1965949.html
1。获取局域网ip
IPAddress ipAddr = Dns.Resolve(Dns.GetHostName()).AddressList[0];//获得当前IP地址
string ip=ipAddr.ToString() ;
string ip=ipAddr.ToString() ;
2。获取公网ip
{ string tempip = ""; try { WebRequest wr = WebRequest.Create("http://www.ip138.com/ips138.asp"); Stream s = wr.GetResponse().GetResponseStream(); StreamReader sr = new StreamReader(s, Encoding.Default); string all = sr.ReadToEnd(); //读取网站的数据 int start = all.IndexOf("您的IP地址是:[") + 9; int end = all.IndexOf("]", start); tempip = all.Substring(start, end - start); sr.Close(); s.Close(); } catch { } return tempip;}
3.如果是ADSL上网,获取公网ip
string tempIP =string.Empty;
if (System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.Length >1)
tempIP = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList[1].ToString();
分类: WinForm
0 0
- C#获取本机局域网ip和公网ip
- C#获取本机局域网IP和公网IP
- C#获取本机局域网ip和公网ip
- C#获取本机局域网ip和公网ip
- C#获取本机局域网ip和公网ip
- C# 获取公网IP和局域网IP
- C#获取本机局域网ip和公网ip的方法
- C#获取本机公网IP
- JSP获取公网IP和局域网IP
- 获取本机IP和获取公网IP
- 获取本机公网IP
- 获取本机公网IP
- iOS开发 获取公网IP和局域网IP地址
- 本机局域网IP获取
- VC--获取本机 局域网IP 和外网IP
- VC--获取本机 局域网IP 和外网IP
- VC--获取本机 局域网IP 和外网IP
- c#获取公网IP
- ACM最大矩形
- linux abrt的用法
- 中断与定时器
- DML、DDL、DCL区别
- CSS3 Object-fit和Object-position
- C#获取本机局域网ip和公网ip
- 字符串匹配(找段落中匹配的单词)
- 1622-5 孔富晨 总结《2016年11月11日》 【连续第42天总结】
- jQuery总结
- HDU 3966 [树链剖分]
- Python Dict and File -- python字典与文件读写
- 约瑟夫环,出圈游戏
- MySQL学习之路_SELECT语句
- 解决pip升级问题:关闭Mac的System Integrity Protection的方法