Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get client IP address in ASP.NET CORE 3.1?

how to get a client IP address in ASP.NET 3.1 when writing code in Web API project

like image 670
Rohit Jadhav Avatar asked Jan 13 '20 06:01

Rohit Jadhav


People also ask

How do I find the client IP address?

Determining IP Address using $_SERVER Variable Method : There is another way to get the IP Address by using the $_SERVER['REMOTE_ADDR'] or $_SERVER['REMOTE_HOST'] variables. The variable in the $_SERVER array is created by the web server such as apache and those can be used in PHP.

What does IP address :: 1 mean?

The simple answer is that: ::1 is the compressed format of IPV6 loopback address 0:0:0:0:0:0:0:1 . It is the equivalent of the IPV4 address 127.0.

What does client IP mean?

Client IP means proprietary systems, software, information, logos, services names, domain names, marks and copyrights the Client uses.

What is Http_x_forwarded_for?

HTTP_X_FORWARDED_FOR is often used to detect the client IP address, but without any additional checks, this can lead to security issues, especially when this IP is later used for authentication or in SQL queries without sanitization.


2 Answers

Use this tutorial. wish it will help you. Get client IP address in Asp.NET core 3

Or just use this line of code in your controller:

var ip =HttpContext.Connection.RemoteIpAddress.ToString()
like image 80
elahe karami Avatar answered Sep 25 '22 15:09

elahe karami


string ipAddress = HttpContext.Connection.RemoteIpAddress.ToString(); 

deviceName = Dns.GetHostEntry(HttpContext.Connection.RemoteIpAddress).HostName;
like image 35
KingRaja Avatar answered Sep 22 '22 15:09

KingRaja