Get Host Public IP through Header in Python - python

I have a service host on Amazon ECS.
It also have load balancer and CloudFront in front of my ECS, below picture is their architecture:
When my service is running, it will need it's own public IP address to record.
And I want get this information without third party library or website. I dig into the fields in HTTP header, I found this in my chrome (see picture below), but I can't access this information by the fields in the header.
My questions is:
Can I get public IP of server without third party library?
(This seems impossible without third party library due to following asked questions)
Get public/external IP address?
Discovering public IP programmatically
How can I get the public IP using python2.7?
Can I get the field like I saw in chrome in python?

You can read remote IP address of AWS Cloud Front host using almost any HTTP client in any language or using command line tools like cURL.
However keep in mind that Cloud Front remote IP address you see in your HTTP client (like Chrome in your example) is not "your" address. It is an IP address of the Cloud Front endpoint nearest to your client. Don't confuse Cloud Front endpoint IP (which is not "yours" and might change) with your Elastic Load Balancer IP (which can be "yours" i.e. reserved for you).

Related

How can I get my public IPV4 address from NAT internal network with python

guys
I just want to look up my public ipv4 address from NAT internal network, I know lots of webpages offering that function, only if you visit them by opening webpages with a browser. The thing I figure out is to extract the IP address information from the webpage with python, I had used python's lib called 'requests', but every time the code response without IP information I anticipate when I visit those webpages which can show my public address correctly in a browser. I guess it is probably because those pages used a code-proof visiting strategy. So is there any way that I can use to get my public IP address with python code, just something like restful service?
public_ip = requests.get('https://ifconfig.me').text
The simplest way to get your public IP is to get it from a REST service, like ifconfig.me, using requests (which you mentioned in your question and needs to be installed with pip). requests.get() sends an HTTP GET request to the REST API and returns a Response object that has a text attribute which contains the content of the response, in this case your public IP address.

Getting Client IP address while using development server in Flask

What I am doing
I have a flask website and I am making it accessible to a client using ngrok tunneling.
What I want
I am trying to get the IP address of the client.
What I have done so far
I have tried these so far,
request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
and
request.environ['REMOTE_ADDR']
But both of them are returning 127.0.0.1. I have also checked out this question But it didn't help me out since the answer written there are for getting client IP's in production server environment whereas I am looking for any method using which I can get IP address of client in the development mode of server which is tunneled using ngrok.
I have two possible methods in my mind,
If I can get the IP address of the connection requester from Ngrok. I don't know is there any way to do it but this can solve my problem.
Or I add something to my javascript code so that whenever the index page loads up it sends an ajax request to the server telling it the IP address of the client. (Correct me if wrong)
In case of Flask , you cannot get the client ip address directly on the server side but you cannot get the IP address if your web app grabs the client ip and then using AJAX request sends it back to the server so that you can log it.
That's the only possible way i think you can do it in flask.

encrypt the http request url on the local machine

my software on the local machine needs to send http request to a specific web server , is there any way to protect the http request url from being found by Packet analyzer software like Wireshark and fiddler.
The sever is not mine, so I can do nothing in the server .
It would be better to show some code, I am an absolutely newbie in encryption .
P.S the server doesn't support https protocol
After some retinking on my question ,I found what I am really want is not let any other guys using packet analyzer software know the server name (host name) my software is sending data to .
so I translate the host name to IP address format, it somewhat hide the host name.
Another question is : for common sites, is the IP address under the host name hardly changing ?

Get an IP adress of a client of a SOAP service

I'm writing a SOAP service using python and soaplib. I need to get IP adresses of all clients of the service to store them to the log file. How can I do that?
One way to do this is to implement a "hook" which is called at different stages of the wsgi executation. See the section "Hooks" in the soaplib readme file for details and the example hook.py in that distribution.
For example, you could implement onMethodExec and then use the wsgi environ.get('REMOTE_ADDR') to obtain the client's IP address and log it.

IP address of domain on shared host

I have domain on a shared hosting provider. How do I find the direct IP address of my domain using Python?
Is it possible to post to a script on my domain using the IP address and not the website itself?
Thanks.
I guess the IP should be static so do you really need to look it up more than once?
You need to specify the domain name so that the webserver knows which host configuration to use if you don't have a dedicated IP or your host is the default for that webserver
import socket
socket.gethostbyname("www.stackoverflow.com")
'69.59.196.211'
will get you the ip address (as a string) of your domain.
However, if it's shared hosting I would think it highly unlikely that you'll be able to access your hosting via the ip - most likely you'll have something like Apache's VirtualHost Directive in place which limits you to only 'seeing' requests to your domain. Requests to the IP address will be served by some default configuration.
Would very much depend on the nature of your hosting.
A curious request ...
To look up a domain name, do something like this:
import socket
ipaddress = socket.gethostbyname('www.bbc.co.uk')
Regarding posting to the IP address:
I don't think it would work in the normal way (like from a browser), because there will probably be many sites held under that address.
But, I guess you could do it in a very manual way, using a programming language (e.g. Python), if you connected a client socket to the site's IP address, but still sent the website's name in the HTTP Host request header.
I don't know if that poses more questions than it answers, and I don't know why you'd want to do either of the above, but there it is.
Good luck!

Categories