我的服务器在局域网中, 我想要得到服务器外网的IP地址,请帮助. 谢谢!如果是通过ip138得到再输出, 就不用说了.
如果是得到是局域网的IP,如:192.168.1.* 这不用说了,
请求帮助, 谢谢!!!!!!

解决方案 »

  1.   

     #region 获取客户端IP地址
            public static string GetClientIP()
            {
                string result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (null == result || result == String.Empty)
                {
                    result = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                if (null == result || result == String.Empty)
                {
                    result = System.Web.HttpContext.Current.Request.UserHostAddress;
                }
                return result;
            }
            #endregion
      

  2.   

     #region 获取客户端IP地址
            public static string GetClientIP()
            {
                string result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (null == result || result == String.Empty)
                {
                    result = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                if (null == result || result == String.Empty)
                {
                    result = System.Web.HttpContext.Current.Request.UserHostAddress;
                }
                return result;
            }
            #endregion
      

  3.   

    hewansongjuan  你好, 我要的是服务器IP地址, 不是客户端的, 谢谢
      

  4.   


    http://topic.csdn.net/u/20100827/11/b4a71038-ee5e-4551-b9d7-70dc4a3029cf.html
    是不是代理服务器?
    http://blog.csdn.net/xiamin/article/details/4489316
      

  5.   

    string userIp = Request.UserHostAddress.ToString();  
      string ipa=Request .ServerVariables ["REMOTE_ADDR"];  
      this.Label1.Text = userIp+"a"+ipa;  
      //主机ip  
      string hostip = Dns.GetHostName();  
      IPAddress[] ips;  
      ips = Dns.GetHostAddresses(hostip);  
      foreach (IPAddress ip in ips)  
      {  
      this.TextBox1.Text = ip.ToString ();  
      }   
      

  6.   


    public   static   string   IPAddressAll 
        { 
          get 
             { 
                string   ip   =   HttpContext.Current.Request.UserHostAddress; 
                string   agentip   =   HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 
                if(!string.IsNullOrEmpty(agentip)) 
                { 
                  //有代理 
                  if(agentip.IndexOf(".")==-1) 
                    agentip   =   null; 
                  if(agentip   !=   null) 
                    { 
                      if(agentip.IndexOf("unknow")!=-1) 
                         agentip   =   agentip.Replace("unknow",   string.Empty); 
                         string[]   temparyip   =   agentip.Replace("   ",   string.Empty).Replace("'",   string.Empty).Split(new   char[]   {   ',',   ';'   }); 
                         //过滤代理格式中的非IP和内网IP 
                         for   (int   i   =   0;   i   <   temparyip.Length;   i++) 
                           { 
                             if   (temparyip   !=   string.Empty   
     &&   IsIPAddress(temparyip) 
     &&   temparyip.Substring(0,   3)   !=   "10." 
     &&   temparyip.Substring(0,   7)   !=   "192.168" 
                             &&   temparyip.Substring(0,   7)   !=   "172.16.") 
                                { 
                                     ip   +=   ","   +   temparyip; 
                                } 
                            } 
                    } 
                } 
                      else 
                          { 
                             agentip   =   null; 
                          } 
                          return   ip; 
                } 
        } 
      

  7.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    public partial class WebStart : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        //获取浏览器版本号
        public string getBrowser() {
            string browsers;
            HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser;
            string aa = bc.Browser.ToString();
            string bb = bc.Version.ToString();
            browsers = aa + bb;
            return browsers;
        }
        //获取客户端IP地址
        public string getIP()
        {
            string result = String.Empty;
            result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (null == result || result == String.Empty)
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (null == result || result == String.Empty)
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            if (null == result || result == String.Empty)
            {
                return "0.0.0.0";
            }
            return result;
        }
        //获取操作系统版本号
        public static string SystemCheck()
        {
            string Agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];        if (Agent.IndexOf("NT 4.0") > 0)
            {
                return "Windows NT ";
            }
            else if (Agent.IndexOf("NT 5.0") > 0)
            {
                return "Windows 2000";
            }
            else if (Agent.IndexOf("NT 5.1") > 0)
            {
                return "Windows XP";
            }
            else if (Agent.IndexOf("NT 5.2") > 0)
            {
                return "Windows 2003";
            }
            else if (Agent.IndexOf("NT 6.0") > 0)
            {
                return "Windows Vista";
            }
            else if (Agent.IndexOf("WindowsCE") > 0)
            {
                return "Windows CE";
            }
            else if (Agent.IndexOf("NT") > 0)
            {
                return "Windows NT ";
            }
            else if (Agent.IndexOf("9x") > 0)
            {
                return "Windows ME";
            }
            else if (Agent.IndexOf("98") > 0)
            {
                return "Windows 98";
            }
            else if (Agent.IndexOf("95") > 0)
            {
                return "Windows 95";
            }
            else if (Agent.IndexOf("Win32") > 0)
            {
                return "Win32";
            }
            else if (Agent.IndexOf("Linux") > 0)
            {
                return "Linux";
            }
            else if (Agent.IndexOf("SunOS") > 0)
            {
                return "SunOS";
            }
            else if (Agent.IndexOf("Mac") > 0)
            {
                return "Mac";
            }
            else if (Agent.IndexOf("Linux") > 0)
            {
                return "Linux";
            }
            else if (Agent.IndexOf("Windows") > 0)
            {
                return "Windows";
            }
            return "未知类型";    }
     }
      

  8.   

    不访问外网服务器,你得不到。因为到底通过了多少个路由器、Proxy,不确定。你必须访问外网服务器,然后通过返回结果带回来IP。这跟访问IP138是一个意思。