RT,谢谢...

解决方案 »

  1.   

    参考:
    http://topic.csdn.net/u/20081214/23/5b74d7ff-5f1f-4298-b94f-5b0c96ef8981.html
      

  2.   

    private void button1_Click(object sender, EventArgs e)
    {
    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..";
    }
    }
      

  3.   

    using System.Net;IPHostEntry IPHost = Dns.GetHostEntry("www.baidu.com");
                IPAddress ip = IPHost.AddressList[0];
                string address = ip.ToString();
                MessageBox.Show(address);