Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active February 4, 2025 03:35
Show Gist options
  • Save mariocesar/b628c91e7b00cca0dca371ac2d54544c to your computer and use it in GitHub Desktop.
Save mariocesar/b628c91e7b00cca0dca371ac2d54544c to your computer and use it in GitHub Desktop.
Check network can resolve and access a host with port

Run me like this. Or maybe not! it's dangerous!

curl -sL "https://gist.github.com/mariocesar/b628c91e7b00cca0dca371ac2d54544c/raw/script.py?v=$(date +%s)" | python3 - google.com:443
import sys
import socket
host, port = sys.argv[1].split(':')
print(f"trying {host}:{port}")
print("socket.gethostbyname")
try:
print(socket.gethostbyname(host))
except Exception as exc:
print(exc)
print("socket.getaddrinfo")
try:
print(socket.getaddrinfo(
host,
port,
proto=socket.IPPROTO_TCP,
type=socket.SOCK_STREAM
))
except Exception as exc:
print(exc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment