我是在公司的局域网内上网,我想知道我的外网IP是多少应该怎么办啊。

解决方案 »

  1.   

    这样的话在你本机似乎是没有办法取到外网IP的,必须在有外网IP的电脑上才行这是我的愚见,不代表实际情况,请高手指点
      

  2.   

    似乎没有办法
    无论是获取硬件信息还是通过 tracert得到的网关地址都是内网地址。
    所以只能通过外面传给你了,你跟另外一台机器通信,那台机器就会知道你的外网地址,让它告诉你。
      

  3.   

    转来的------------------static string GetIP()
    {
        Uri             uri = new Uri("http://www.ikaka.com/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("GB18030"));
        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;
        return string.Empty;
    }
      

  4.   

    取外网IP俺不清楚,小弟这里有一个取真实IP的,希望对各位有启发:
    public static string GetRealIP()
    {
    string ip;
    try
    {
    HttpRequest request = HttpContext.Current.Request; if (request.ServerVariables["HTTP_VIA"] != null)
    {
    ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
    }
    else
    {
    ip = request.UserHostAddress;
    }
    }
    catch (Exception ex)
    {
    throw ex;
    } return ip;
    }
      

  5.   

    private void button2_Click(object sender, System.EventArgs e)
    {
    System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; 
    if ( addressList.Length>1)

    this.textBox1.Text = addressList[0].ToString();
    this.textBox2.Text = addressList[1].ToString();
    }
    else
    {
    this.textBox1.Text = addressList[0].ToString();
    this.textBox2.Text = "Break the line...";
    }
    }
    正常情况下textBox2.Text返回的是外网IP  不过要是你自己拨号
    我用局域网上的 只有同学的主机可以获得 我只能获得本地IP