Created
February 12, 2020 08:59
-
-
Save michtesar/b00714dcf8a7bcea8ae26e62e3e5abc9 to your computer and use it in GitHub Desktop.
Find IP address by its hostname (butforce)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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