1

自分のサイトにアクセスしているコンピュータのアドレス IP (LAN ip) を取得したい。

どうすれば入手できますか?

4

4 に答える 4

1

できません。

ブラウザはローカル IP を HTTP ヘッダーで送信しないため、それを取得する方法はありません。ルーターの外部 (インターネット) IP のみを取得します。

于 2012-12-16T10:59:02.237 に答える
0

この関数を使用します。

 public string GetLanIP()
    {
        IPHostEntry host;
        string localIP = "?";
        host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (IPAddress ip in host.AddressList)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                localIP = ip.ToString();
            }
        }
        return localIP;

    }
于 2012-12-16T12:17:08.447 に答える
0

asp.net を使用していると仮定します。その場合、Request.UserHostAddress を使用してクライアントの IP アドレスを取得できます。

于 2012-12-16T10:30:51.863 に答える
0

Method 1:

You can get that by using below mentioned link.

List the IP Address of all computers connected to a single LAN

Method 2:

You can try below one also.

public string GetUserIP()
    {
        string ipList = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        if (!string.IsNullOrEmpty(ipList))
        {
            return ipList.Split(',')[0];
        }

        return Request.ServerVariables["REMOTE_ADDR"];
    }

Method 3:

System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.GetValue(0).ToString();

I hope this will help to you.

于 2012-12-16T10:34:24.267 に答える