局域网中的主算机如何取外网IP地址 局域网中的主算机如何取外网IP地址? 代码 谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string html = Encoding.GetEncoding(936).GetString(new WebClient().DownloadData("http://www.7y8.com/V/ip.asp"));string ip = Regex.Match(html, @"(?<=你的IP是\D+)[0-9.]+").Value; static string GetPage(string url) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); try { using (HttpWebResponse res = (HttpWebResponse)req.GetResponse()) { using (StreamReader sr = new StreamReader(res.GetResponseStream())) { return sr.ReadToEnd(); } } } catch (System.Exception e) { return e.Message; } finally { req.Abort(); } } // 通过外部网站得到本机的外部IP static string GetOuterIP() { string patt = @"IP: \[(? <IP>[0-9\.]*)\]"; string url = ""; return Regex.Match(GetPage(url), patt).Groups["IP"].Value; } static void Main() { foreach (IPAddress ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { Console.WriteLine(ip); } Console.WriteLine(); Console.WriteLine(GetOuterIP()); }http://topic.csdn.net/u/20100514/10/c856bd9f-e860-4430-990e-a6f2f80694f1.html http://www.7y8.com/V/ip.asp打开看下 求教serialport类如何得到新收到的短信? 显示隐藏的子窗体失败! 学C#何时可以编出一般的win应用程序? 菜菜鸟问题:vs2003为什么不能显示cookie的中文? winform里面我在窗体里面按CTRL+Enter,就可以运行Button事件! 请教用三层结构做c#+asp.net全站程序最先要从哪下手?是不是要先做好框架啊? 请高手指点 查找添加到Panel控件中的控件问题?大家新年快乐,请帮帮忙,急等 109错误 C#怎么控制输出数的宽度 一个错误,求解答 菜鸟求解
string ip = Regex.Match(html, @"(?<=你的IP是\D+)[0-9.]+").Value;
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
try
{
using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
{
using (StreamReader sr = new StreamReader(res.GetResponseStream()))
{
return sr.ReadToEnd();
}
}
}
catch (System.Exception e)
{
return e.Message;
}
finally
{
req.Abort();
}
}
// 通过外部网站得到本机的外部IP
static string GetOuterIP()
{
string patt = @"IP: \[(? <IP>[0-9\.]*)\]";
string url = "";
return Regex.Match(GetPage(url), patt).Groups["IP"].Value;
} static void Main()
{
foreach (IPAddress ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
Console.WriteLine(ip);
}
Console.WriteLine();
Console.WriteLine(GetOuterIP());
}
http://topic.csdn.net/u/20100514/10/c856bd9f-e860-4430-990e-a6f2f80694f1.html
打开看下