Skip to content

Instantly share code, notes, and snippets.

@jacobtomlinson
Created October 31, 2024 11:01
Show Gist options
  • Save jacobtomlinson/02325b89c276a8c4f2d07ab1b493cb89 to your computer and use it in GitHub Desktop.
Save jacobtomlinson/02325b89c276a8c4f2d07ab1b493cb89 to your computer and use it in GitHub Desktop.
Say hello to computers all around the world
import contextlib
import codecs
import subprocess
import pandas as pd
# Load list of global nameservers and country code information
print("Loading data sources...")
nameservers = pd.read_csv("https://public-dns.info/nameservers.csv")
countries = pd.read_csv("https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes/raw/refs/heads/master/all/all.csv")
# Merge and reduce list to one IPv4 server in each country
ipv4_nameservers = nameservers[~nameservers.ip_address.str.contains(":")]
countries = countries.rename(columns={"name": "country_name"})
merged = pd.merge(ipv4_nameservers, countries, left_on="country_code", right_on="alpha-2")
targets = merged[["ip_address", "country_name"]].drop_duplicates(subset=["country_name"])
# Ping a server in each country to say hello
print(f"Found servers in {len(targets)} countries, let's say hello to each one!")
for ip_address, country_name in zip(targets.ip_address, targets.country_name):
with contextlib.suppress(subprocess.CalledProcessError):
subprocess.check_output(["ping", "-c", "1", "-t", "1", "-p", codecs.encode(b"hello", "hex"), ip_address])
print(f"Hello {country_name} 👋")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment