自分のサイトにアクセスしているコンピュータのアドレス IP (LAN ip) を取得したい。
どうすれば入手できますか?
自分のサイトにアクセスしているコンピュータのアドレス IP (LAN ip) を取得したい。
どうすれば入手できますか?
できません。
ブラウザはローカル IP を HTTP ヘッダーで送信しないため、それを取得する方法はありません。ルーターの外部 (インターネット) IP のみを取得します。
この関数を使用します。
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;
}
asp.net を使用していると仮定します。その場合、Request.UserHostAddress を使用してクライアントの IP アドレスを取得できます。
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.