I have a simple Apache+Flask website running inside a basic Vagrant+VirtualBox environment. I can access my site fine at 127.0.0.1:8080.
The question & problem is, how do I configure Vagrant to pass the real clients IP address to Apache+Flask?
request.remote_addr always returns 10.0.2.2 no matter what client is connecting from within my LAN.
For example the machine running Vagrants IP is 192.168.1.5. From a client i.e. another laptop on my LAN with IP of 192.168.1.7, would hit the site # 192.168.1.5:8080, but 192.168.1.7 is not the remote_addr in vagrant/flask+apache, its always 10.0.2.2
Thanks!
The most easy way to do that would be a bridged network. The VM will receive an IP address in your (outside) network, e.g. 192.168.1.10.
See https://docs.vagrantup.com/v2/networking/public_network.html on how to configure that.
Related
Excuse me, I am a beginner to networking here.
I am trying to connect to my friend's network. She is approximately 10 kilometers from me. I am the client and she is the server that I want to connect and send messages.
I tried to connect two computers on my own LAN. It worked!, but when I change internet of another laptop to mobile hotspot and try to connect to that laptop. Of course, different IP. It doesn't work anymore!
My questions are:
Is it possible to connect to one or more remote computers that are on the different internet provider or network using python socket module?
Is it possible to receive and send messages between a computer on WIFI LAN and a computer on WIFI mobile hotspot using python socket module?
What do I probably need to make the connection?
Yes.
Yes.
Ensure that your friend's server has a routable IP address.
If your client is attempting to connect
across the public internet
to an rfc1918 private address,
it will fail in the way you reported.
You need to ensure the client is
connecting to a reachable server IP.
It must be routable,
and there must not be a firewall in between
which filters and discards your packets.
I'm trying to run a bottle server such that some routes run on one port, and the others run on another port.
However, reading through the documentation has proved no fruits: https://bottlepy.org/docs/dev/bottle-docs.pdf.
Is this possible with bottle?
No, you can not route to multiple ports.
A server needs an address and a port to listen to. So, routing will be done after address and port are set in server.
I have 3 servers A, B and C that already have IP addresses assigned by the DHCP server.
I wanted to request a fourth IP from the DHCP server that I can use as a floating IP between my service.
Is there a simple way to do this via python or bash/shell commands? Everything I've read is always talking about renewing the machines IP address not pooling another available IP.
I have a server running by using python's base http server. The host name used is '127.0.0.1' the local host, and the port number is set to 8000. I have the public ip address of the computer operating this server.
If I wanted to send a http get request to this from another computer, what would I type into my browser?
Sounds like you've got your server process running on the wrong interface. 127.0.0.1 is not a hostname but an IP address, specifically the local loopback address. It is not reachable from any other machine (unless something's gone tragically wrong with your network configuration).
You can run anything you like on the 127.0.0.1 interface, and no one else can directly connect to it from a remote machine. That's pretty much the point --- it's for testing programs that use the Internet Protocol, and (in recent years) for starting single-user servers without worrying about security. (Python 2's SimpleHTTPServer does this, as do some personal wikis, and I think iPython Notebook.)
The public address for the host running your Web server is a completely unrelated network interface, with its own hardware and its own port 8000. It doesn't know or care that you've got something listening on some other interface's port 8000, so it should refuse attempts to connect to that port.
Since you didn't post any code, I have no idea what you need to change to get your server running on the correct interface. Assuming you've more or less followed the example in the BaseHTTPServer.HTTPServer docs:
def run(
server_class=BaseHTTPServer.HTTPServer,
handler_class=BaseHTTPServer.BaseHTTPRequestHandler,
):
server_address = ('', 8000) # <----= Replace the string.
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
That server_address tuple is a string containing the IP address ('1.2.101.202' or whatever), followed by an integer port number. So replace the string with your host machine's public-facing IP address.
Note that port 8000 is outside the reserved range (0 up to but not including 1024), so it's possible that some unrelated service is already using that port. (Numerous applications are already squatting port 8000.) If so, you'll just have to choose another port number. You can chose anything from 1024 up to but not including 65536, but as with 8000, someone else might already be using it.
Depending on your operating system and its security setup, you might not have permission to open a socket that listens on an arbitrary port number. If so, that's between you and your ISP or sysadmin.
http://yourip:port/func
yourip is your public ip.
port is 8080
func is your registered function.
and also make sure you port is opened
I wrote a simple python script using the SocketServer, it works well on Windows, but when I execute it on a remote Linux machine(Ubuntu), it doesn't work at all..
The script is like below:
#-*-coding:utf-8-*-
import SocketServer
class MyHandler(SocketServer.BaseRequestHandler):
def handle(self):
data_rcv = self.request.recv(1024).strip()
print data_rcv
myServer = SocketServer.ThreadingTCPServer(('127.0.0.1', 7777), MyHandler)
myServer.serve_forever()
I upload it to the remote machine by SSH, and then run the command python server.py on the remote machine, and try to access to xxx.xxx.xxx.xxx:7777/test with my browser, but nothing is printed on the remote machine's teminal...any ideas?
UPDATE: Problem solved, it's a firewall issue, thanks you all.
You are binding the server to 127.0.0.1, the IP address for localhost. This means the server will only accept connections originating from the same machine; it won't recognize ones coming from another machine.
You need to either bind to your external IP address, or bind to a wildcard address (i.e. don't bind to any particular IP address, just a port). Try:
myServer = SocketServer.ThreadingTCPServer(('0.0.0.0', 7777), MyHandler)
You are binding to 127.0.0.1:7777 but then trying to access it through the servers external IP (I'll use your placeholder - xxx.xxx.xxx.xxx). 127.0.0.1:7777 and xxx.xxx.xxx.xxx:7777 are different ports and can be bound by different processes IIRC.
If that doesn't fix it, check your firewall, many hosts set up firewalls that block everything but the handful you are likely to use
Try with telnet or nc first, telnet to your public ip with your port and see what response you get. Also, why are accessing /test from the browser? I don't see that part in the code. I hope you have taken care of that.