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 )
Related
I'm creating a simple chat app using Python.
The server code is in the Linux VM (I am using Virtual Box), and the client code is in the Windows 10 computer where the Virtual Box is installed.
I'm trying to connect it with the Python socket.
It works when I ping both machines to each other.
My problem is what port should I put in the client code:
Client
import socket
import subprocess
cliente = socket.socket()
try:
cliente.connect(('192.168.1.33',9090))
cliente.send("1")
I tried every port available; however, nothing works. I think I am missing something to make this work.
First, You need to make sure that the port number passed to bind function in server code in Linux VM is the same port number used by connect function in your client.
Check this simple server-client example in python which is using port 12345 :
https://www.tutorialspoint.com/python/python_networking.htm
Second, (based on your comments) the IP address that should be used in client connect function is the IP address of the machine running the server code which is in your case the Linux VM. Try to run the shell command ifconfig in the Linux VM to get the IP address.
If this address didn't work you can change the network settings of the virtual machine to bridged instead of NAT and try again the ifconfig command and get the new IP address.
Doing SSH from the host machine to Linux Virtual machine will work great!!
I did the port forwarding: I put the server on the virutal machine, and connected the client from the host to the virtual machine. That worked well.
But now, when I tried to do this in the reverse direction, it did not.
First thing I did is a port forwarding with the following parameters:
host port: 35001
port to forward: 35001
virtual machine ip: 192.168.40.130
It was done succesfully.
After that, when I did this (server script but on cmd (shell) on host):
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
s.bind(("0.0.0.0",35001))
I get this error:
Only one usage of each socket address (protocol/network address/port) is normally permitted
I believe that is because there is a process listening on the port 35001.
It is VMware(NAT) listening on 35001, after I forwarded the port (I find that out using netstat).
So how to make a server on the host, make it listening to port 35001, and be able to connect to it from a virtual machine?
It is windows 10 pro, python3, a windows 7 VM. Firewalls are disabled. I don't want to use a bridged connection.
The Vmware portforwarding is just a process, created by the vmware service, with the following parameters:
it runs on your host machine
allocates the TCP port 35001
listens to incoming TCP connections
forwards them to the TCP 35001 of your guest machine IP
This is what is does, and no more.
As your started the port forwarding, this process was started and allocated the 35001 TCP port on your host.
This is why your python script, on the host, did not work. It could not allocate the 35001 TCP port of your host again.
VMware creates a virtual network. Your virtual machines see this virtual network. No ethernet card belongs to it, but it looks as if it would. It has the 192.168.40.0-192.168.40.255 IP address range. Also your host machine is on this virtual network, probably with the IP 192.168.40.1. Your guest machine sees it as a router.
This is so for the host-only, bridged or NATted virtual network types. The virtual network types only affect, what your host machine does with the packets to forward them between the virtual and your physical network.
To run a server on your host, what you can connect from your guest, you do not need any port forwarding. Simply stop it, so your python script will run. Then, connect 192.168.40.1:35001 from your guest.
Is there anyway to use TCP/IP communication between a Beaglebone Black and PC connected only by USB cable?
I'm try to create an oscilloscope using a Beaglebone Black ADC connected to a computer using a USB cable.
I know that when I connect my BBB (Beaglebone Black) I can access it by its ip 192.168.7.2 and I see this device on my local network if I use ipconfig on cmd (I'm using Windows 10), and if I ping on this IP I receive the data. But on the Beaglebone side I cannot see my computer on its network or ping to my computer local address.
Also I tried to use a basic python socket connection tutorial between my PC and BBB, here (PC as server and BBB as client):
https://pymotw.com/2/socket/tcp.html
And I receive connection denied on my BBB.
Just to remember, I'm not pretending to solve it using an Ethernet cable or WiFi module.
I'm still working on DHCP via RNDIS and Gadget Ethernet on Arch Linux, but on Ubuntu it works flawlessly. You may need some additional commands, but the general idea is to enable Gadget Ethernet using g_ether on the beaglebone.
I am assuming that you are using Angstrom. You will likely need to modify /etc/network/interfaces and ensure that it is configured for DHCP.
[BeagleBone Black]
insmod g_ether
echo "g_ether" > /etc/modules-load.d/gadget_ethernet
iface usb0 inet dhcp (/etc/network/interfaces)
Connect to USB port on Ubuntu. Share the internet connection using Ubuntu (require IPv4 to complete). Ensure that you have the BeagleBone SSH service enabled and the port opened on both Ubuntu and BeagleBone.
[Ubuntu]
nmap 10.42.0.0/24
ssh to the IP address that Ubuntu gave to the BeagleBone via USB.
I have Arch Linux Arm installed. For your application, I recommend Arch Linux Arm, which installs without a graphical user interface.
You can send an outgoing ping so you know that a TCP/IP connection can be established. However that is an outgoing connection and you are wanting to accept and incoming connection.
Check your firewall settings on your development machine, if the incoming connection is denied there you will not be able to connect. The outgoing ping might make it through the firewall but the incoming connection can still be denied. Because you know you can connect I would recommend checking the firewall rules allow an incoming connection to be made.
If you need to debug further go and get Wireshark and see what traffic is going over the wire.
You need to set up a Static IP address in order for the BBB to use the USB Ethernet connection.
Derek Molloy explains it here: http://derekmolloy.ie/set-ip-address-to-be-static-on-the-beaglebone-black/
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.
***Sorry for using the Term Host & Guest I see that has confused things slightly. By Host I mean Client which listens on your desired port for incoming connections and by Guest I mean Server which attempts to retrieve the IP of your pre-defined Dyndns.org address. Then tries a connection. You may say that's 'backwards' but for my applications scenario that's the fitting method. Since I'm in the United Kingdom my public IP I mentioned starts with 91.
Here's two diagrams to explain if the Server connections to the Client running on the same OS.
Ubuntu - Linux
Connection over 127.0.0.1 = SUCCESS!
Connection over public IP = SUCCESS!
Windows - Laptop TinyXP - Laptop Vista - VM TInyXP
Connection over 127.0.0.1 = SUCCESS!
Connection over public IP = FAILED!
So the problem is Windows. I've tried the Twisted examples and again they work over local host but not via public IP on Windows so it can't be my script. It can't be the firewall as the two TinyXP installations don't have the default firewall, whilst the Vista laptop did have the default shipped one however I unblocked the process after it popped up prompting me. and thus did not yield any better results.
To forward the port I went to my Orange Livebox's configuration page (192.168.1.1) and forwarded the TCP port 4005. Just as I did for when I tested it on Ubuntu (Instead using the 4004 port) so it can't be that either. I attempted to use wireshark (Found it hard to understand). I started capturing packets on all ports, then fired up the Client followed by the Server. Resulting entries are here http://pastebin.com/ddytpydz
Alas I have no more ideas on what I can do. The twisted version I'm using is one of the latest whilst the Python version is 2.6 Any one have some ideas?
So maybe there is some windows limitations for listenings pors. As far as I remeber some Windows can have max 5 ports open for listening. But I don't remeber exacly.
Sounds like a firewall problem. I would add either the port or python.exe to the approved list.
Are any of the Windows machines joined to a domain?