Skip to content

Instantly share code, notes, and snippets.

@michtesar
Created February 12, 2020 08:59
Show Gist options
  • Select an option

  • Save michtesar/b00714dcf8a7bcea8ae26e62e3e5abc9 to your computer and use it in GitHub Desktop.

Select an option

Save michtesar/b00714dcf8a7bcea8ae26e62e3e5abc9 to your computer and use it in GitHub Desktop.
Find IP address by its hostname (butforce)
import socket
def find_address(hostname="localhost", address_range=range(255)):
for address in address_range:
print(address)
try:
host = socket.gethostbyaddr("192.168.1.{}".format(address))
except socket.herror:
continue
if host[0] == hostname:
print(host[-1][0])
break
if __name__ == "__main__":
find_address(hostname="my_hostname")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment