追求新生活 名字2008

活着的意义

vs2003如何获得ip地址和主机名

代码:
string  s_ip;  
   if(Request.ServerVariables["HTTP_VIA"]!=null)  
    s_ip=Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();        
   else  
    s_ip=Request.ServerVariables["REMOTE_ADDR"].ToString();
   Label19.Text ="ip地址:"+s_ip+" 主机:"+System.Net.Dns.GetHostByAddress(s_ip).HostName ;
把最后一句分离成
s_ip 和System.Net.Dns.GetHostByAddress(s_ip).HostName 就可以知道是ip地址和主机名了。

posted on 2008-06-20 10:59  pyman  阅读(493)  评论(0编辑  收藏  举报

导航