我现在是局域网。我使用了下面代码查到的是内网的IP地址
System.Net.IPAddress[] ips;
ips = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
textBox1.Text = ips[2].ToString();
请问怎么编写查询外网IP地址的代码呢? 谢谢!
System.Net.IPAddress[] ips;
ips = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
textBox1.Text = ips[2].ToString();
请问怎么编写查询外网IP地址的代码呢? 谢谢!
解决方案 »
- 变量名、函数名用中文可以吗?
- 按理说在gb2312字符集的文本中不能输入繁体,为什么下面这样却可以输入呢?
- 输入字符串的格式不正确....请大家来解决一下!!!!
- 各位大俠,.NET的WebForm的哪些代碼是在服務器端運行。哪些又在客戶端運行啊??謝謝先:)
- 怎么取消Alt+F4组合键关闭窗口?
- 调用 DLL 的限制?
- 请教大牛们event关键字的问题
- 如何对齐DataGrid中的列控件
- 菜鸟寻:水晶报表CrystalReportViewr的使用实例!
- 为什么WebBrowser控件在MDI子窗体加载时出错?
- 【紧急求助】excel 导入到 Listview的问题
- VS2010 C# winform 编辑并继续功能出错 高分求解
httprequest 抓取上面的数据。
string strUrl = "http://www.ip138.com/ip2city.asp"; //获得IP的网址了
Uri uri = new Uri(strUrl);
WebRequest wr = WebRequest.Create(uri);
Stream s = wr.GetResponse().GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.Default);
string all = sr.ReadToEnd(); //读取网站的数据
int i = all.IndexOf("[") + 1;
string tempip = all.Substring(i, 15);
string ip = tempip.Replace("]", "").Replace(" ", "");
return ip; 我抄的,如果有偏差的地方,自己改改
"<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="refresh" content="0;url=http://city.ip138.com/city0.asp"> <title>IP地址查询</title> </head> <body> <script type="text/javascript"> location.href="http://city.ip138.com/city0.asp"; </script> </body> </html>"