Advertisement
osteth

DNSmap.py

Aug 18th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #!/bin/env/python
  2.  
  3. # Title: DNSmap.py
  4. # Author: Seth Wahle
  5. # Contact: Seth [at] sethwahle.com  Twitter: @SethWahle
  6. # comments:
  7. '''
  8. This script is a quick way to get the IP and hostname of a host, and then the same for all the computers in the same
  9. range as the host.
  10. You can also import this file to use these functions in other scripts.
  11. '''
  12.  
  13. '''This bit will cause the output of the script to be written to a file instead of to the console.
  14. this for some reason also seems to dramatically improve script runspeed.'''
  15. import sys
  16. sys.stdout = open('DNSmap.txt', 'w')
  17.  
  18.  
  19. def IP():
  20.     '''This funtions retruns the current systems IP address.'''
  21.     import socket
  22.     return socket.gethostbyname(socket.gethostname())
  23.    
  24. def nslookup(IP):
  25.     '''Function that will determine a systems hostname when supplied with an IP address'''
  26.     import socket
  27.     name = socket.gethostbyaddr(IP)
  28.     return name[0]
  29.  
  30. def get_range(IP):
  31.     return ".".join(IP.split(".")[0:3])
  32.  
  33. if __name__ == "__main__":
  34.     print('Current Host\'s Network Information:')
  35.     print('\n')
  36.     print('IP address: ' + IP())
  37.     print('Hostname: ' + nslookup(IP()))
  38.     print('\n')
  39.     print('This hosts Neighbors include:')
  40.     print('\n')
  41.    
  42.     ipRange = []
  43.     for i in range(1, 254):
  44.         ipRange.append(get_range(IP()) + '.' + str(i)) # <-- put your IP range here in the first set of ' '
  45.  
  46.     for e in ipRange:
  47.         try:
  48.             print(e + ', ' + nslookup(e))
  49.         except:
  50.             print(e + ', Host Unavailable')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement