Networking and computer to computer communication

I have been reading up on python stuff for a time now and I cant seem to locate any information about some more tedious networking things.

I want to simply send a packet from Computer1, located roughly 1 foot in front of me, to another computer that is located roughly 200 miles from me. I would say that this conundrum uses a thing called the internet to accomplish this. All of the stuff I find is to connect to localhost or to connect to a website (which i have actually used python to do quite a bit). The problem lies with the fact that the nitty gritty details are always left out and I want those details.
Simply put: How do I setup a server/client, on computers 1 & 2, and send a packet to them via the internet. How would I go about making a simple “HELLO” and from there sending it from my computer, to my router, to my ISP and out to the vast limitless ether of the internet… but whats this!!! That computer is also on the internet! Meaning received by THAT ISP, (and how do you get that ISP clients IP?), THAT router, and THAT computer2’s ip dynamically assigned by the router.

I would say, and I could be wrong here, that its a more complex subject than most are used to… thus why it seems impossible to find anything on the internet about it… But does any one know how to open and listen on a port, on 2 separate computers, send a raw packet (TCP/UDP/whatever) and then read it on the receiving end from the internet? I will handle the client/server side of things but what about that middle road? Anyone know?
Just a note: using something as simple as whois in a terminal only needs an IP address… but with billions of devices out there, its not that simple to find one computer on the vastness of the web. I would imagine (simple local network) only deals with your routers assigned IPs and the FULL address probably uses crap like subnets and netmasks and other junk. Or, if im lucky, simply wrapping the packet a special way and let the ISP handle it from there which may simplify this problem immensely…

Anyway, enough of my blabbering… summary:sending raw packets a distance via the internet. Example source appreciated.

You’re probably looking for the socket module. The stdlib docs have
client and server implementation example code:

If you want to go even deeper down the rabbit hole, check out the
Scapy project:

Hope that helps!

thank you kindly. Ill check that out.

That is a private address. There’s not any real way for a computer on the internet to connect to that address directly. So that address cannot (easily) be a server.

If you can browse the internet from the machine, it is likely that you have a router that is running NAT and is tracking/reformatting packets so that it can be used for client communication.

Some NAT gateways will allow externally-visible servers to be run on a machine by setting up connections for particular ports. But that setup is specific to your gateway, not to the code you are running on the local machine.

I have been trying for a time to find out how to send outside of my network. Do you know if its possible? Or do you always need a middleman like a registered, paid-for server to receive and then forward (like a chat room). The more I dig around, the more it seems that a 3rd party server is required.

Is there a way to get a global ipaddress outside of the routers assigned local ips and then send packets to it? To put it really simple: can I send a simple packet, saying ‘hello’ (5 small characters), to your computer directly?

Depends on what you mean by “send”. Generally, you can create a client and it should be able to connect to a public resource (because your NAT gateway is doing the translation). This code “sends” data to google and listens for a response using only the socket module. Does it work on your machine?

(If you really wanted to do web traffic, there are much better ways. But this shows a simple TCP connection with some text traffic)

(From Python 3 - simple HTTP Request with the Socket module | HackLAB)

import socket
"""code from"""

target_host = ""

target_port = 80  # create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# connect the client

# send some data
request = "GET / HTTP/1.1\r\nHost:%s\r\n\r\n" % target_host

# receive some data
response = client.recv(4096)
http_response = repr(response)
http_response_len = len(http_response)


And when I run it on my machine, I get a nice response from google:

$ python3 /tmp/
b'HTTP/1.1 200 OK\r\nDate: Tue, 11 Jan 2022 03:59:25 GMT\r\nExpires: -1\r\nCache-Control: private, max-age=0\r\nContent-Type: text/html; charset=ISO-8859-1\r\nP3P: CP="This is not a P3P policy! See for more info."\r\nServer: gws\r\nX-XSS-Protection: 0\r\nX-Frame-Options: SAMEORIGIN\r\nSet-Cookie: 1P_JAR=2022-01-11-03; expires=Thu, 10-Feb-2022 03:59:25 GMT; path=/;; Secure\r\nSet-Cookie: NID=511=IkltE0zYIZFnoC-19XUVirgRg7LJb3EeuXg_f3WOfiY7galYxd30pN_rJgCPtnnqivPqLLm7Oa6O1WCoGFGFZ0nHpqhxwpBh4g5d_4YBuvShLzhtAVBaP4N1DPJZkJLUk1-7TMO75_VGQrywHIpPl62Yf2NY3ktkCClHWn4X07c; expires=Wed, 13-Jul-2022 03:59:25 GMT; path=/;; HttpOnly\r\nAccept-Ranges: none\r\nVary: Accept-Encoding\r\nTransfer-Encoding: chunked\r\n\r\n4a12\r\n<!doctype html><html itemscope="" itemtype="" lang="en"><head><meta content="Search the world\'s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you\'re looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="xoDwZwWaBDYygjTN0tNLyA==">(function(){{kEI:\'nQDdYY7ZLIrP0PEP3daXkA4\',kEXPI:\'0,1302536,56873,6058,207,4804,2316,383,246,5,1354,4013,923,315,1122515,1197'

Only if my computer has a public address and a public service listening for it. The above code does that for google because it is running a webservice that satisfies both of those conditions.

It seems that it is as i suspected that a dedicated server, mine or a thirdparty, is a requirement. Thanks for the pointers. Ill look into that and keep digging. There was a list of things I wanted to whip up focusing on bypassing the middleman… Anyway, thanks fellas for the help.

My residential broadband ISP allows this by default for IPv6. I set
up my home router to request a routed prefix via DHCPv6-PD, and then
advertise that in the route announcements to the systems in my home
network. Those systems bind global IPv6 addresses within that
assigned public prefix via SLAAC and, so long as I allow connections
in to them through the firewall, are reachable by other
IPv6-connected systems on the Internet directly with no need for
address translation.