如何获取公网IP? RT,谢谢... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考:http://topic.csdn.net/u/20081214/23/5b74d7ff-5f1f-4298-b94f-5b0c96ef8981.html private void button1_Click(object sender, EventArgs e){textBox1.Text = Dns.Resolve(Dns.GetHostName()).AddressList.GetValue(0).ToString(); //内网IPtextBox2.Text = GetIP(); //外网IP}static string GetIP(){Uri uri = new Uri("http://www.ciker.net/ip/index.asp");System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);req.Method = "POST";req.ContentType = "application/x-www-form-urlencoded";req.ContentLength = 0;req.CookieContainer = new System.Net.CookieContainer();req.GetRequestStream().Write(new byte[0], 0, 0);System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)(req.GetResponse());StreamReader rs = new StreamReader(res.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312"));string s = rs.ReadToEnd();rs.Close();req.Abort();res.Close();System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(s, @"您的IP:(?<IP>[0-9\.]*)");if (m.Success){return m.Groups["IP"].Value;}else{return "Failed..";}} using System.Net;IPHostEntry IPHost = Dns.GetHostEntry("www.baidu.com"); IPAddress ip = IPHost.AddressList[0]; string address = ip.ToString(); MessageBox.Show(address); C# 从dll文件读取 dd C++函数中需要传入地址符( GetInf(int itan , PW_TAG &*Stag) ),要把这个函数转成C#调用,后面这个输入参数 怎么该?? 请问如何在两个From中传递参数 第一次用SharePoint,遇到麻烦,有劳高手帮忙解决,顶帖有分 C#里面如何采集mic的声音?? 在c++程序中调用被c编译器编译后的函数,为什么要加extern"C"? 如何用c#代码实现生成坡度? 关于C#中树的问题? 引用spatialite库 局域网文件传输```大家都来试试吧 新人XML求助
http://topic.csdn.net/u/20081214/23/5b74d7ff-5f1f-4298-b94f-5b0c96ef8981.html
{
textBox1.Text = Dns.Resolve(Dns.GetHostName()).AddressList.GetValue(0).ToString(); //内网IP
textBox2.Text = GetIP(); //外网IP
}static string GetIP()
{
Uri uri = new Uri("http://www.ciker.net/ip/index.asp");
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = 0;
req.CookieContainer = new System.Net.CookieContainer();
req.GetRequestStream().Write(new byte[0], 0, 0);
System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)(req.GetResponse());
StreamReader rs = new StreamReader(res.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312"));
string s = rs.ReadToEnd();
rs.Close();
req.Abort();
res.Close();
System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(s, @"您的IP:(?<IP>[0-9\.]*)");
if (m.Success)
{
return m.Groups["IP"].Value;
}
else
{
return "Failed..";
}
}
IPAddress ip = IPHost.AddressList[0];
string address = ip.ToString();
MessageBox.Show(address);