Skip to content

Instantly share code, notes, and snippets.

@wsummerhill
Created November 16, 2022 17:32
Show Gist options
  • Save wsummerhill/17f997ea493e38efda03df6fd03f2eb6 to your computer and use it in GitHub Desktop.
Save wsummerhill/17f997ea493e38efda03df6fd03f2eb6 to your computer and use it in GitHub Desktop.
#Quick Python script to loop through hostnames from file and resolve their IPs
import socket, sys
hostsFile = sys.argv[1]
with open(hostsFile) as file:
for line in file:
try:
host = line.strip()
ip = socket.gethostbyname(host)
print(f'Host: {host} = {ip}')
except socket.gaierror as e:
#print(f'Error: IP not found for {host}')
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment