Get an IP adress of a client of a SOAP service - python

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.

Related

Python requests get website using custom dns

I need to access a specific server and it just responses to connections with a specific DNS server. So before connecting to that website I need to set my system DNS servers to custom IPs. That's ok, but now I'm working on a python script with a requests module and I want to access that server. How can I set custom DNS IPs to requests session to do GET function with those DNS servers?
I should say that I just need a JSON file from that server, so It's just exhausting to change DNS servers every time.

Get Host Public IP through Header in 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).

How to Map an IP to hostname in python without writing in hosts file

I am using windows 7 and python 2.7 I created local https server with redirect url to server as its IP address. I created cert file for https using openssl.
Then I mapped my local system IP(172.16.17.84) to myapp.nobies.in in hosts file of windows.
So my server redirect url becomes https://myapp.nobies.in:443.
By doing this IP mapping in host file, I am not getting SSL error.
But, I want to distribute my app to others, so, writing in host file through python code is not desirable, as it needs administrative privileges.
So, is there any way to assign/map this IP with hostname instead of making an entry in hosts file.
Have you considered just creating the certificate for the IP address? That wouldn't be much more fragile (probably less fragile, actually) than having to manually add the domain name to hosts files. See https://stackoverflow.com/a/11710762/138772 and https://stackoverflow.com/a/8444863/372643 for more info on that.
An alternative, but one probably requiring more work, would be to include a local DNS server in your app that redirects the domain name to your IP address. I can't really say what the best one to use for that would be, though.

log incoming ip addresses in web.py

I'd like to log the IP addresses of machines that access my web.py application. How can I access this data within the web.py framework? I'm happy to send the address to my own logger.
Use web.ctx['ip'] to get the remote ip address. Here is a link which explains what's in the context.

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