检查客户端的IP地址 [英] checking the ip address of client

查看:98
本文介绍了检查客户端的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

i使用以下代码检查IP地址,但它没有给出确切的IP地址

------------ -------------------------------------------------- -------------------------------

friends,
i have used the following code for checking ip address but it is not giving exact ip address
---------------------------------------------------------------------------------------------

public string IpAddress()
      {
          string strIpAddress;
          strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
          if (strIpAddress == null)
          {
              strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
          }
          return strIpAddress;
      }
      protected void btnipcheck_Click(object sender, EventArgs e)
      {
          string str;
          try
          {
               str = IpAddress();
               Session["ip"] = str;
               Label1.Text = Session["ip"].ToString();
          }
          catch
          {
              Label1.Text = Session["ip"].ToString();
          }
      }



------------------------- -------------------------------------------------- ---------------

i已经在当地主机上测试了

它给o / p 127.0.0.1

但我的IP地址不同:10.25。--- .---

----------------------- -------------------------------------------------- --------

那么获取客户端机器的确切IP地址的其他代码是什么。


------------------------------------------------------------------------------------------
i have tested on local host
it is giving o/p 127.0.0.1
but my ip address is different :10.25.---.---
---------------------------------------------------------------------------------
so what is the other code for getting the exact ip address of client machine.

推荐答案

Of当然它给你127.0.0.1!你在DEV机器上测试它!请求没有出去上网,所以它不会使用10.xxx路线。



如果你想要IP请求来自,你必须在一台单独的机器上运行该网站。然后你可以从你的机器发出请求并获得真正的IP地址。
Of course it''s giving you 127.0.0.1! You''re testing it on your DEV machine! The request doesn''t go out to the internet and back in so it''s not going to use the 10.x.x.x route.

If you want the IP the request came from, you''ll have to run the site on a seperate machine. Then you can make a request from your machine and get the real IP address.


我在Windows EXE程序中使用它:

I use this in a Windows EXE program:
string strHostName = System.Net.Dns.GetHostName();
string strIPAddress = "";
System.Net.IPAddress[] objAddressList = System.Net.Dns.GetHostEntry(strHostName).AddressList;
for (x = 0; x <= objAddressList.GetUpperBound(0); x++) 
{
    if (objAddressList[x].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) 
    {
        strIPAddress = objAddressList[x].ToString();
        break; 
    }
}









我通过Google搜索在在asp页面获取IP地址 - 客户端 [ ^ ]

Response.Write("Local Machine Host name is "+Dns.GetHostName()+"<br>");
         string hostname = Dns.GetHostName();
         IPHostEntry ipEntry = Dns.GetHostByName(hostname);
         IPAddress[] addr = ipEntry.AddressList;
         for (int i = 0; i < addr.Length; i++)
           {
               Response.Write(string.Format("IP Address {0}: {1} ", i, addr[i].ToString()) + "<br>");
           }





以及识别用户的IP地址 [ ^ ]



这篇关于检查客户端的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆