I'm trying to set up two servers on my laptop using the script in https://github.com/misheska/foundations-of-python-network-programming/blob/master/python2/02/udp_remote.py.
As far as I understand, I can set a server just by typing
$ python udp_remote.py server
I want to start another server using my external IP, that I get using:
$ wget -q -O - http://myexternalip.com/raw
XXX.XXX.XXX.XXX
Then the server should be set with
$ python udp_remote.py server XXX.XXX.XXX.XXX
right???
Your syntax is correct (other than your IP4s being only 3 bytes long), but there are a couple reasons why you're having trouble:
It's not possible to bind to the same port twice on the same interface. Because the script has a fixed port number, you won't be able to run more than one instance unless your laptop has multiple interfaces.
Your WAN IP address will only be resolvable to an interface if your laptop itself is actually assigned that address. If the laptop is connected to a router and is assigned a local address, you won't be able to use the WAN address to specify the interface.
You cannot bind to an IP address that is not bound to an interface on the computer. If you require port forwarding to be set up on a router then consult your network administrator.
Related
I have a python script that uses PySimpleGuiWeb. I want to host it on my server and connect to it from another computer. But the script is running on 127.0.0.1. Can I somehow change this, or is there another way?
From the host device running the pysimplegui python script, you can likely load the gui via 127.0.0.1:###### through a browser (where ##### is your port). This is because it's hosted and being accessed from the same device.
Accessing from another device on the same network: try using the IP of the device hosting the pysimplegui followed by the same port as is used locally by host device to access gui.
e.g. 172.20.10.5:######
IP of the host device found via:
Linux(terminal):
ifconfig
Mac(terminal):
ifconfig
Windows(command prompt):
ipconfig
You can make the IP of your gui host device static and according the pysimplegui you can make the port static too, therefore the GUI should be always found at the same IP:port externally (given the static IP holds and doesn't get reallocated and that port isn't blocked for any reason by network etc.)
Update:
In addition, with some further reading, optional arguments to a 'Window' include:
web_ip='0.0.0.0', web_port=0
https://github.com/PySimpleGUI/PySimpleGUI/blob/master/PySimpleGUIWeb/PySimpleGUIWeb.py
I want to do a connection between a computer simulating being a server and another computer being a user, both with Linux.
In the first computer I've created a directory called "server" and in that directory I've done the following command:
python3 -m http.server 8080
Then I can see that directory going to the localhost. But what I want is to see that localhost from the other computer, I tried with wget, and the gnome system of sharing files but none of them worked, and I'm not seeing any solution online.
I'm not sure I fully understand your question but if you want to reach your folder from an other computer with your command python3, you can use the option -b followed by an IP address used on your linux.
All you need to do is get the IP of the server using ifconfig command.
ifconfig | grep 192 make sure not to use the broadcast address part.
Now logon to the other machine and hit the command
http://192.168.71.145:8080
And it should work.
Here I have assumed that your IP is 192.168.71.145 and the port is 8080.
Just change the IP and port as per your values.
If I'm understanding your question correctly you want to connect to the server from another machine on the same network.
If so you can run hostname -I on the server to output to the local IP address of the server, you can then use this on the other machine to connect to it (provided they are on the same network)
I'm trying out the command python http.server from the command line, and am trying to access the server. I can access easily from localhost, but whenever I try to use a remote connection, I am unable to connect.
I've tried different ports, and it doesn't look like my firewall is blocking any connections.
From the command line, I run
python3 -m http.server 8000
which returns
Serving HTTP on 0.0.0.0 port 8000 ...
However, I can only connect to the server from localhost.
sudo iptables -S
returns the following:
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
I expect to be able to connect from a remote host with the url http://10.247.30.125:8000 (my ip address), but I am unable to do so. The same url works fine on localhost.
I figured out what was going on. Did some reading about IP and NAT, and noticed that any ip address beginning with a 10 is reserved for private ip addresses. So, trying to connect to 10.247.30.125:8000 from anywhere other than my own network (so while not connected to my wifi) doesn't work. To be able to connect from an external network, I would need to set up port forwarding (like Reedinationer suggested), and I would need to use my router's public IP address rather than my computer's private IP address. I would set up a port forward from my router to direct external traffic to my computer, which would allow me to connect to my personal computer from an external network.
Thanks to everyone who responded!
port is missing from the url try this url it should work "http://10.247.30.125:8000"
I want to set up a Django development server that both my computers and smart phones can access whilst on my network via wifi.
I've already set up a development server that my computer can access on http://127.0.0.1:8000/. However, my other devices can't.
The Django documentation says:
"Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled)."
I've found my "public IP address" and tried to use this by:
python manage.py runserver xx.xx.xxx.x (where this is my public ip address) but i get a "Command error: 'xx.xx.xxx.x' is not a valid port number or address:port pair."
I then tried the same with :8000 after the IP address, but got an error "Error: That IP address can't be assigned to".
Then python manage.py runserver 0.0.0.0:8000. The command line reports "Starting development server at ...", but when i try "http://0.0.0.0:8000/" on Chrome, i get a "This site can't be reached error".
Is it something to do with my windows firewall settings?
Please can you someone help me? Thanks!
This is very late, but I run onto an additional issue following this post. If you are using a rhel distro based and if firewalld
is enabled it might be blocking the connection. So for testing purposes run:
systemctl stop firewalld
0.0.0.0 is not a real address, it's a placeholder that just says that the server is not bound to a specific IP.
If you run on 127.0.0.1, it will only answer to queries that where addressed to 127.0.0.1, so localhost only.
Using your private address (192.168.0.x most often), it will only answer to queries to this address (so opening with the 127.0.0.1 should not work, but sometime does depending on the implementation)
So, if you use 0.0.0.0, it will answer to anything.
tl;dr : use 0.0.0.0 and connect using :
127.0.0.1 from this computer
your computer's private ip address for other computers inside your lan
you public IP for computers outside your lan. Note that this will require additional configuration on your router
You will need your local ip address not public.
You can get the local ip in windows machine by typing the following command in cmd : ipconfig .
On Linux type the following in terminal : ifconfig
The ip address will be of the form 192.168.0.101[Example]
So in your phone's browser type : 192.168.0.101:8000
I am trying to send a string from the windows to the linux vmware on the same machine.
I did the following:
- opened a socket on 127.0.0.1 port 50000 on the linux machine and reading the socket in a while loop. My programming language is python 2.7
- send a command using nc ( netcat ) on 127.0.0.1 port 50000 from the windows machine ( using cygwin ).
However, I dont receive any command on the linux machine although the command sent through windows /cygwin is successful.
I am using NAT ( sharing the hosts IP address ) on the VMWARE Machine.
Where could be the problem?
When you use NAT, the host machine has no way to directly contact the client machine. All you can do is usign port forwarding to tell vmware that all traffic directed to the designated ports on the host is to be delivered to the client. It is intended to install a server on the client machine that can be accessed from outside the host machine.
If you want to test network operation between the host and the client, you should configure a host-only adapter on the client machine. It is a virtual network between the host and the client(s) machine(s) (more than one client can share same host-only network, of course with different addresses)
I generally configure 2 network adapters on my client machines :
one NAT to give the client machine an access to the open world
on host-only to have a private network between host and clients and allow them to communicate with any protocol on any port
You can also use a bridged interface on the client. In this mode, the client machine has an address on same network than the external network of the host : it combines both previous modes
Your problem is multi-fold
1st
setup Ubuntu-VM's IP-network & a static IP-address of this guest O/S.
VALIDATE:
$> ifconfig // list all setup Ubuntu interfaces/addresses
2nd
if your VM guest is hosted as being connected to a different IP-network, than your Windows system, make sure there is a connectivity and route between these two hosts ( VMnet configurator in VmWare will help a lot to solve this ).
VALIDATE:
C:\ ping <aUbuntuVmIpADDRESS> // prove an online visibility Win->UbuntuVM
3rd
make sure your Windows O/S permits the use your selected TCP-port#
VALIDATE:
list all allowed / add if-needed TCP-port# in Windows Firewall setup
4th
make sure your python sends all socket-traffic not to a Windows local loopback interface <127.0.0.1>, but towards the visible IP-address of the Ubuntu-VM guest O/S, ( setup as per step-1, verified as per step-2 ) using an unused, permitted TCP-port# ( verified/setup as per step-3 )