In my code in want to print the ip address of the client system.My front end and back end codes are in same server.My client systems ip is 192.168.2.3(not actual) and server up is 192.168.38.1(not actual).When i run the services its getting that local host address only (ie localhost).
request.getRemoteAddr();
I am using this code to get the ip.
Why its happening and how can I resolve that?
Related
I am using my own squid proxy server,when I check my ip address on whatismyip.com, it show the ip address of my proxy server.
But, when I check on speedtest.net, I found that they can track my client IP.
Is there any ways to prevent my real IP being detected ???
Your IP is provided by your ISP (internet service provider) and speedtest.net picks up your gateway/router.
Thus "trying" to hide behind a proxy would not have any effect.
I have a server with 4 ip addresses and four clients that each register their ip address with a service. Each client runs the same ruby script that connects via a TCP socket to the service.
The problem I have is all four scripts are connecting via the same IP address so three are receiving authorisation errors because they have the wrong ip address.
Is it possible to tell the TCP client to use a specific ip address?
I have a REST service running on Mac OS X, which im currently accessing using "localhost:8888" and "10.0.2.2:8888"
I want to access the same service from another computer which is in the same network.
I disabled the firewall also and I typed
nc -v 192.168.1.3 8888
and got the result as
nc: connectx to 192.168.1.3 port 8888 (tcp) failed: Connection refused
currently i use localhost (to access using java application) and 10.0.2.2 (to access using android application runs in the simulator) which both runs on the same machine which the server runs too.
I want to put the android application to my phone and give the machine ip addess ( because if i connect to internet via wifi, it'll be in the same local area network) i should be able to access my service runs on my machine.
can some one please tell me what im doing wrong here? Thank you
You can't access localhost from your front end code. It needs to refer to the server's name or address.
The localhost address should be 127.0.0.1, which is in the loopback range of addresses. Any address in the 127.0.0.0/8 block can never appear anywhere on any network, nor can any address in that block be used as a source or destination address outside a host. It is not possible for one host to access anything in that address range on another host.
The goes back at least as far as RFC 990, ASSIGNED NUMBERS:
The class A network number 127 is assigned the "loopback" function,
that is, a datagram sent by a higher level protocol to a network 127
address should loop back inside the host. No datagram "sent" to a
network 127 address should ever appear on any network anywhere.
RFC 1122, Requirements for Internet Hosts -- Communication Layers:
(g) { 127, }
Internal host loopback address. Addresses of this form MUST NOT
appear outside a host.
Also RFC 3330, Special-Use IPv4 Addresses:
127.0.0.0/8 - This block is assigned for use as the Internet host loopback address. A datagram sent by a higher level protocol to an
address anywhere within this block should loop back inside the host.
This is ordinarily implemented using only 127.0.0.1/32 for loopback,
but no addresses within this block should ever appear on any network
anywhere [RFC1700, page 5].
Sinatra app.
<%= request.ip %>
gives 127.0.0.1 IP address if looked at from local server.
gives 83.245.226.68 IP address if looked at from Heroku server, no matter from which device.
So I guess it returns server's IP address and not client's. How do I find out what client's IP address is then? Did I misunderstand request.ip method?
This happens when the HTTP Server in front of the Rack HTTP Server (e.g. used for load balancing, ssl, etc) is not forwarding the client IP address to the Rack HTTP Server. In that case you get the IP address of the HTTP Server.
This can be configured on HTTP Servers like Nginx and Apache and you get the client IP address in request.ip.
As far as I know Heroku is doing it in a way that the client IP address is in a header called "x-forwarded-for", which is a comma separated list of IP addresses, the last element is the client ip.
Sinatra:
env['HTTP_X_FORWARDED_FOR'].split(',').last
Rails:
request.headers['x-forwarded-for'].split(',').last
http://ipfuck.paulds.fr/
We've been recently getting hammered by this Firefox plug-in. It sends a fake IP in the headers so when our nginx web server picks up the IP it is a fake one.
Is there any way to get a real IP address or block out requests that have this plug-in installed?
There is actually no client IP entries in any HTTP Headers. There are only some un-official proxy headers which are added to a request, so that a proxy server can tell you the real ip of the connecting client (since the tcp socket will only reveal the IP address of the proxy server).
The plugin you linked to adds those proxy headers, to "fake" a proxy request, by adding a X-Real-IP: 1.2.3.4 or X-Forwarded-For: 1.2.3.4 header to the request. But no one forces you to use that IP address (which can be fake, like the 1.2.3.4 example here), you can always use the IP address of the socket that initiated the connection - which will be the client's real IP address if he uses the mentioned plugin.
Within the location section of your nginx configuration, you get the socket IP address through the $remote_addr variable. To retrieve the "fake" IP address, you can use $http_x_forwarded_for or $http_x_real_ip variable.
If you are using any application/cgi backend, you usually can examine the full headers and the socket IP address (i.e. in PHP you should check $_REQUEST and $_HEADERS variables)