What is IP address '::1'?
::1
is the loopback address in IPv6. Think of it as the IPv6 version of 127.0.0.1
.
See http://en.wikipedia.org/wiki/Localhost
IP Address of the machine in PHP gives ::1 but why?
::1
is the actual IP. It is an ipv6 loopback address (i.e. localhost). If you were using ipv4 it would be 127.0.0.1
.
If you want to get a different IP address, then you'll need to connect to the server through a different network interface.
Nodejs ip address result ::1
If you are working on localhost this is normal try logging this on server you will get the address of the user.
Or you might be running nginx or similar reverse proxy in front of your node server in this case you should set proper headers
for nginx you need this ones
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
check herefor more info
How to store ip addresses of visitors in database in php?
'::1' means it is your localhost IP Address.
::1 == 127.0.0.1
You can try this one also.
$ip=$_SERVER['REMOTE_ADDR'];
echo "IP address= $ip";
If your application hosted on same machine from where you are trying to request it will always return '::1', It means LocalHost. else it will return client IP Address.
Finding local IP addresses using Python's stdlib
import socket
socket.gethostbyname(socket.gethostname())
This won't work always (returns 127.0.0.1
on machines having the hostname in /etc/hosts
as 127.0.0.1
), a paliative would be what gimel shows, use socket.getfqdn()
instead. Of course your machine needs a resolvable hostname.
How to determine a user's IP address in node
In your request
object there is a property called socket
, which is a net.Socket
object. The net.Socket
object has a property remoteAddress
, therefore you should be able to get the IP with this call:
request.socket.remoteAddress
(if your node version is below 13, use the deprecated now request.connection.remoteAddress
)
EDIT
As @juand points out in the comments, the correct method to get the remote IP, if the server is behind a proxy, is request.headers['x-forwarded-for']
EDIT 2
When using express
with Node.js:
If you set app.set('trust proxy', true)
, req.ip
will return the real IP address even if behind proxy. Check the documentation for further information
Signification of / in ip address
First off, you need to understand that an IP address has 32 bits.
Next, you need to understand that a "network" involves machines that are specifically numbered to keep them together. If you have (say) 11 computers that are going to be together in a network, then their IP addresses will all have their "left" side in common:
xxxxxxxx xxxxxxxx xxxxxxxx xxxx0001
xxxxxxxx xxxxxxxx xxxxxxxx xxxx0010
xxxxxxxx xxxxxxxx xxxxxxxx xxxx0011
...
xxxxxxxx xxxxxxxx xxxxxxxx xxxx1101
xxxxxxxx xxxxxxxx xxxxxxxx xxxx1110
The number after the slash indicates the number of bits that the machines all have in common. In this case, whatever value the (reserved) first IP address
xxxxxxxx xxxxxxxx xxxxxxxx xxxx0000
has, the network is identified as XXX.XXX.XXX.XXX/28
Related Topics
What Is a Regular Expression for Parsing Out Individual Sentences
Is the Size of a Form in Visual Studio Designer Limited to Screen Resolution
Group by Variable Integer Range Using Linq
Removing Dynamically Created Controls in C#
Is There a C# Generic Constraint for "Real Number" Types
Which Blocking Operations Cause an Sta Thread to Pump Com Messages
C# Static Member "Inheritance" - Why Does This Exist at All
Converting String Format to Datetime in Mm/Dd/Yyyy
Parsing Performance (If, Tryparse, Try-Catch)
Using SQLdataadapter to Insert a Row
Efficient Cartesian Product Algorithm
Generics: Casting and Value Types, Why Is This Illegal
How to Delay Shutdown and Run a Process in Window Service
Get the Default Timezone for a Country (Via Cultureinfo)
How to Get the Index of the Highest Value in an Array Using Linq