This is a duplicate thread. The client IP address is generally useless in a web application because many users can have the same IP address. You can never get the actual user's machine IP address you only get the user's gateway to the Internet or network
endpoint.
Can you explain why you need the IP address? What is the problem you are trying to solve?
i want to get ip client that open my website in your browser . my site show ip address client that chrome is right but in ie , mozilla is wrong.
explain(i run my site in iis in windows server 2019, with dns server .when search my website with ipaddress server dont have problem but when search with host name server have problam in mozilla , ie )(for example http:\\192.168.50.86 , http:\\webserver
)
i write in controller:
public ActionResult GetIpWeb()
{
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress==""||ipAddress==null)
{
// ipAddress = Request.UserHostAddress + " test " ;
The code shown runs on a web server not the client browser. Your requirement is not possible for a browser based solution. You have to write a custom client and not use the browser for your requirement. As explained many times in your similar thread,
the client IP address is of no use in a web application. Why do you need the IP address? What do you do with the IP address?
Member
39 Points
143 Posts
how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 01, 2021 06:50 AM|aabedeni056|LINK
hello
i use dns server in my server , i want to search my website with host name :http:\\webserever
when i use under code in my website for get ipaddress client: mozilla , ie dont show me but chrome shows .
public ActionResult GetIpWeb()
{
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress==""||ipAddress==null)
{
ipAddress = Request.ServerVariables["REMOTE_ADDR"];
}
ViewBag.IPAddress = ipAddress;
return View();
}
i want to use under code instand of above code .
public static void DoGetHostEntry(string hostname)
{
IPHostEntry host = Dns.GetHostEntry(hostname);
// Console.WriteLine($"GetHostEntry({hostname}) returns:");
foreach (IPAddress address in host.AddressList)
{
// Console.WriteLine($" {address}");
// return (address);
}
}
but i dont khow to how write code in controller & view in mvc .
Contributor
3550 Points
935 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 01, 2021 07:24 AM|l.laxmikant|LINK
the following code will give you all IP address and record entry from your website
Member
39 Points
143 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 04, 2021 08:06 AM|aabedeni056|LINK
hello . i write website for get ip adress client in local network (for dns server ) .
i dont khnow to how get ip address client when write my site in browser with host name server (httpL\\webserver)
i dont know to how use under code in controller , view :
public static void DoGetHostEntry(string hostname)
{
IPHostEntry host = Dns.GetHostEntry(hostname);
Console.WriteLine($"GetHostEntry({hostname}) returns:");(i dont know how to write in controller )????????????
foreach (IPAddress address in host.AddressList)
{
Console.WriteLine($" {address}");?????????????????
}
}
help me please ....
All-Star
53711 Points
24042 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 04, 2021 02:04 PM|mgebhard|LINK
This is a duplicate thread. The client IP address is generally useless in a web application because many users can have the same IP address. You can never get the actual user's machine IP address you only get the user's gateway to the Internet or network endpoint.
Can you explain why you need the IP address? What is the problem you are trying to solve?
Member
39 Points
143 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 07, 2021 06:15 AM|aabedeni056|LINK
hello . i have local network with work group .
i want to get ip client that open my website in your browser . my site show ip address client that chrome is right but in ie , mozilla is wrong.
explain(i run my site in iis in windows server 2019, with dns server .when search my website with ipaddress server dont have problem but when search with host name server have problam in mozilla , ie )(for example http:\\192.168.50.86 , http:\\webserver )
i write in controller:
public ActionResult GetIpWeb()
{
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress==""||ipAddress==null)
{
// ipAddress = Request.UserHostAddress + " test " ;
ipAddress = Request.ServerVariables["REMOTE_ADDR"];
}
ViewBag.IPAddress = ipAddress;
return View();
}
in my view :
@{Html.RenderAction("GetIpWeb", "Home");}
but i want to change my controller that i can get ip from dns or show in every browsers but i dont khnow how ????
how to use under code in my website ;maybe it be right .
public static void DoGetHostEntry(string hostname) { IPHostEntry host = Dns.GetHostEntry(hostname); Console.WriteLine($"GetHostEntry({hostname}) returns:"); foreach (IPAddress address in host.AddressList) { Console.WriteLine($" {address}"); } }
All-Star
53711 Points
24042 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 07, 2021 11:59 AM|mgebhard|LINK
Mozilla is functioning as expected. It's your understanding that's wrong.
The code shown runs on a web server not the client browser. Your requirement is not possible for a browser based solution. You have to write a custom client and not use the browser for your requirement. As explained many times in your similar thread, the client IP address is of no use in a web application. Why do you need the IP address? What do you do with the IP address?
All-Star
58474 Points
15793 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 08, 2021 05:11 PM|bruce (sqlwork.com)|LINK
to convert the ipv6 address to ipv4, check the family type
Member
39 Points
143 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 13, 2021 05:01 AM|aabedeni056|LINK
hello. thanks . i get ip server when i use this code . but i want ip address client than visited my web .
i access to ipaddress client in chrome to this code :
public ActionResult GetIpWeb()
{
string ipAddress = Request.ServerVariables["REMOTE_ADDR"].ToString();
if (string.IsNullOrEmpty(ipAddress))
{
ipAddress = Request.ServerVariables["REMOTE_ADDR"];
}
ViewBag.IPAddress = ipAddress;
return View();
}
but i cant to access to ip address client in mozilla , ie . i dont why ?????????????????????????
i see this in my website :
fe80::c847:bd70:ccf7:6c87%15
All-Star
58474 Points
15793 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 14, 2021 12:48 AM|bruce (sqlwork.com)|LINK
as we keep telling you, that is the ipaddress. it is just ipv6 format. you must convert to ipv4 if that is what you want.
Member
39 Points
143 Posts
Re: how to use DoGetHostEntry(string hostname) in controller , view for my website ?
Feb 20, 2021 11:26 AM|aabedeni056|LINK
hello
thank you
my problam is right .
ipv6 disable in windows server , it solved my problem.