I have just written some python server and client using tcp protocol. I am using linux, and want to connect to a windows machine which isn't in my local network. How can i do that? I know it is something about NAT, but i can't find out how to do it properly. Could you please give me step by step guide? Thanks.
Just use sockets? You need to ensure that the network the windows laptop is on is configured to forward a specified port to the laptop. (means it can be accessed externally) You can then use sockets to connect to the laptop on the port you designate.
Related
I am trying to monitor network traffic coming in and out of my VM**. My VM is connected to a socket via TCP (IP, PORT) with the python socket library. Once connected, I am sending a stream of bytes to the socket and then close the connection. The VM runs Ubuntu 18.04 LTS. The connection is made in a VPN tunnel.
How do I capture the traffic for the source and destination while my python script runs? I have tried to work with scapy and Wireshark/pyshark, but the documentation I found did not help me a lot.
Does anyone have an idea how I could do this? I am using python 3
I use wireshark to capture packets, you can filter out the destination and source (as flags to), here's the docs. Is the VPN using some kind of security to encrypt information (such as TLS)?
In the filter insert:
ip.src==your.local.ip.addr && ip.dst==your.VM.ip.addr && ip.proto=="TCP"
What could happen is that the VM tries to get updates and wireshark can pickup a lot of packets, it can mess up your search for the information in the sockets (byte stream).
You also can try stop some Ubuntu services to prevent the internet use, but I cant tell you how to disable all.
Do you want to pickup that byte stream with a sniffer and convert into a person's eye?
If that's the case, it is advanced stuff I can't explain.
Hope I could help.
I wonder and i've been trying everything to get my program with python sockets to work remotely. When I say remotely is like, I run the server in my computer and my friend at his house can run the client and connect to my server. Is this possible without using Hamachi? Pls let me know, because I'm already dying by trying so many things and installing and uninstalling programs.
You have to activate port forwarding on your router so that everything that comes on the specific port is forwarded to your local IP (and the port should be open).
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 coded up the simple server and client on this page:
https://wiki.python.org/moin/TcpCommunication
In the code the port 5005 is specified, but when I run them, the server reports that other ports were used (e.g. 5807, 5810). Why is this?
(I'm running Anaconda python 2.7.8 through pycharm on Windows 7).
Different ports, because this Source port for client and it's taken randomly.
Target Server Socket 5005, must working fine.
I'm writing a Python script which connects to remote hosts over a (super complicated) SOCKS/SSL tunnel. I am able to establish connections to IPs in a remote intranet on any port.
What I'm hoping to do is set up this python script to use IP addresses in the local loopback range (127.0.x.x) to become (maybe with the help of the hosts file) a 'replica' of the remote systems, and hence enable me to use applications which don't support proxies. The problem is that I don't always know what ports they're trying to connect to. It seems the only way to work this out is to bind sockets to all 65536 ports, which seems a little crazy. So two questions:
Is it crazy? Can I just set up a python list of sockets from 1-65536?
Or is there a better way I should be doing this? Can I monitor connections to an IP somehow and bind the ports just before they're needed?
I want to avoid using too much platform-dependent or non-python code if possible.
EDIT: To clarify, I'm only writing the client here - I have no control over the server. Believe me, if I had control over the server side of it I would not be doing it with SOCKS/SSL/CRAM :)
What about going lower level and interfacing a library designed for network analyzers like pycap?
This way you could detect all connection attempts and find the ports that you need to expose or may be you can just route the packets directly assuming the library in addition to packet detection can also do packet injection (pypcap page says this feature is experimental).
This would IMO make sense in python only for slow applications however...
Pycap seems to be developed for linux, but the core capturing is done by libpcap and for windows there is a similar library winpcap.
Matt,
If using windows your best shot is something like OpenVPN over the tunnel. OpenVPN requires only one TCP port/stream and gives you a pair of virtual interfaces with full connectivity.
[updated]
It may be possible using a TUN/TAP driver on the client side. See this unix version for ideas.