Get public client IP in a Flask App? - flask

I want to log the public WAN IP of a client trying to authenticate on a Flask application.
Actually, any method I tried return me the LAN IP of the client.
My stack is an Apache 2.2 server using mod_wsgi to serve the Flask application.
Methods I tried :
request.remote_addr
request.access_route # The list contain only one value which is the LAN IP
request.environ['REMOTE_ADDR']
How could I get the public IP ?
Thanks for any help.
EDIT uniqueness:
I have no proxy set and don't have the "X-Forwarded-For" header.
I don't get a "127.0.0.1" but the LAN IP of the client.
For exemple, for the moment my LAN IP is "10.192.132.148" and my colleague LAN IP could be "10.192.132.149", but our public WAN IP is for both "193.xxx.xxx.xxx".
I'm looking for a way to get this last one in my Flask application.

Ok, finally I got the explication ... the test server was visible only via a connection through a VPN network, so the server was seeing my computer directly just like if it was on my LAN.

Related

Can server host different domain in same port?

I am trying to understand how to host different apps in server, so can server host different domain in same port.
For example, I have domain1 and domain2 both hosted at port 443. Can this be done?
I am doing this in IIS server.
A single web IIS server can host different domain in same port. However, in order IIS to distribute HTTP requests correctly, each website has to be identified with some unique value. In case of an IIS website, it consists of three attributes that make up a unique combination for each website. These are:
a TCP port number
an IP address
a host header (host name)
The information about the hosted websites is stored in the ServerBindings attribute of the IIS metabase in the following format: IP:Port:Hostname. Thus, if you want to host multiple websites on the same port and IP address, you will have to use a unique Host header. What is it? Host header is a part of an HTTP request to the server sent by a client that specifies which website it is addressed to. Accordingly, this host header must be specified on the side of the web server, and the DNS contains the correct record that matches the hostname and the IP address of the IIS web server.
Let’s suppose that you have a website running on IIS and listening 443 port. And you need to bind second website to the same port. In the IIS Manager, create another website with the name TestSite, which files will be located in c:\inetpub\TestSite (do not specify the hostname yet). After you click OK, a warning appears that you cannot use the binding *:443 for both sites.
The binding '*:443:' is assigned to another site. If you assign the same binding to this site, you will only be able to start one of the sites. Are you sure that you want to add this duplicate binding?
Agree to this warning. So you have got another site bound to port 443, you cannot start it without stopping the first site.

web service show localhost not IP in SOAP

I created a web service named WildflyTest and a method called HelloWorld and deployed it to my wildfly 11 server,the server ip is 10.10.9.151.I tried to test using SoapUI, and I can open the wsdl address http://10.10.9.151:8086/WildflyTest/HelloWorld?wsdl. But when I tested it in SOAP Ui, when I created a new request, the address is http://localhost:8086/WildflyTest instead of 10.10.9.151.Can anyone give me some suggestion where to check the reason? Thx.
The issue is with your bind address. By default, public interface is configured to listen on the loopback address of 127.0.0.1. So if you start WildFly as: ./bin/standalone.sh
Then the WildFly default page can be accessed as http://127.0.0.1:8080. Usually, /etc/hosts provide a mapping of 127.0.0.1 to localhost, and so the same page is accessible at http://localhost:8080. 8080 is the HTTP port where all applications are accessed.
On a multihomed machine, you may like to start WildFly and bind public interface to a specific IP address. This can be easily done as:
./bin/standalone.sh -b=10.10.9.151 //your server ip
Now the applications can be accessed at http://10.10.9.151:8080.
Refer following links for more info:
Bind WildFly to a different IP address
How to configure JBoss to bind to a different IP ?

I have a website running on local server ... need help making it public

Note: The ip addresses given are not the exact addresses. They are just for examples
I have a website built on flask running on a linux server that is using the internal ip address and a specific port... 192.168.10.10:1001. I know that the works on other computers on the same wifi.
How can I make the ip address public so that I can access the website without the wifi (outside network)? I know my the external ip address of the server... 100.250.250.25.
I have set up port forwarding so that I can 'access' my server from outside the network... 192.168.10.10:1000. I have accessed the server using the port forwarding but again it was on the same network. (Extra Question) Is that enough to access my server outside the network (or even using 100.250.250.25:1000)?
This applies to django as well because I have websites with django that I would like to use my server as well in the future. (Hopefully 192.168.10.10:1002).
You need to deploy your apps in live server like VPS. For the demonstration, you can try Heroku, pythonanywhere. You will find these tutorials available on other sites.

Access virtual machine from remote server

In my work we use VirtualBox for development so sometimes it gets a little bit tricky when it comes to testing.
Actually I'm working on a payment platform and I have to integrate with PayPal Instant Payment Notifications.
The idea is that when a Paypal transaction is approved, PayPal sends an IPN message to my server and that is the problem.
Is there a way I can make my local development server available so PayPal can access it?
Thanks in advance.
I assume your server is running inside the VirtualBox, right?
So you will have to give the VirtualBox machine an IP that your company router can relay the PayPal IPN message to. That IP should also be a static IP (not by DHCP) so the routing on the router could be set accordingly.
(The following works well, I have done it successfully numerous times)
To do that:
Setup the VirtualBox to have the IP from the company router: In VirtualBox adapter go to the 'settings' of that said VirtualBox, click on 'Network' and change 'Attached to' to 'Bridge Adapter'.
Launch the VirtualBox and change the IP of the machine to a static IP allowed by the company router.
Create on the company's router a routing ('Virtual Server') from a specific socket to this static IP. For example, for socket 1234: http://YourDomain.com:1234
Then you give the PayPal server this domain with socket. any communication on this socket would be routed directly to your server inside the VirtualBox.
Hope that helps!

publish jax-ws service on public ip

I've a simple jax-ws web service that on localhost works fine with the clients, but now I want to publish the web service on a public ip, so the clients can interact with it through wan network instead lan network.
I signed to no-ip dns service provider and defined my host like "myname.no-ip.info".
In my code i start the service in this way:
Endpoint.publish("http://localhost:8080/baseStationProvider", new BaseStationProvider());
and the browser at http://myname.no-ip.info:8080/baseStationProvider#wsdl doesn't show the wsdl.
If i start the service in this way:
Endpoint.publish("http://myname.no-ip.info/baseStationProvider", new BaseStationProvider());
compiling the code, it raise this exception:
Server Runtime Error: java.net.SocketException: Unresolved address
Any idea to problem and/or how to do what i need?
thanks in advance
This seems likely to do with routing and firewalls as opposed to web service publication etc. Ignoring the web-service aspect, can you even reach your server when you use this in your browser:
http://myname.no-ip.info:8080/
?
Which should look the same as
http://localhost:8080/
If not, then it is probably DNS/Routing/Firewalls that you need to check. Diagnostics that will help there are:
1) can the machine you are testing on resolve the DNS name mynam.no-ip.info? nslookup, ping, traceroute/tracert
2) is there a firewall blocking port 8080 from reaching local host? If the route from the internet to your host hits a firewall (which it will) that firewall will have to forward the request.
Good luck.