Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request.ServerVariables["LOCAL_ADDR"] returns "::1"

Tags:

asp.net

I need to get the server's IP address so that this can be sent along with a Key/Value string collection to a Payment Gateway provider.

I'm running localhost, and Request.ServerVariables["LOCAL_ADDR"] is returning ::1

The validation error I'm getting is returned from Sage Pay:

The ClientIPAddress format is invalid. Should not include leading zero''s, and only include values in the range of 0 to 255.

Why is this, and how do I get a valid IP address to send?

like image 411
Curtis Avatar asked Sep 18 '25 20:09

Curtis


1 Answers

Disable IPv6 on your local network adapter. ::1 means 'LOCALHOST'in IPv6. Then you'll get the normal IPv4 127.0.0.1

Anyway ::1 is a *VALID* IP address..

More on LOCALHOST definition: http://en.wikipedia.org/wiki/Localhost

For IPv4 communications, the virtual loopback interface of a computer system is normally assigned the address 127.0.0.1 with subnet mask 255.0.0.0. Depending on the specific operating system in use (notably in Linux and Microsoft Windows) and the routing mechanisms installed, this populates the routing table of the local system with an entry so that packets destined to any address from the 127.0.0.0/8 block would be routed internally to the network loopback device.

In IPv6, on the other hand, the loopback routing prefix ::1/128 consists of only one address ::1 (0:0:0:0:0:0:0:1 in full notation, the address with a one at its least significant bit and zero otherwise) is explicitly defined as the loopback address,[6] though additional addresses may be assigned as needed to the loopback interface by the host administrator.

like image 91
Tisho Avatar answered Sep 20 '25 13:09

Tisho