Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env/python
- # Title: DNSmap.py
- # Author: Seth Wahle
- # Contact: Seth [at] sethwahle.com Twitter: @SethWahle
- # comments:
- '''
- 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
- range as the host.
- You can also import this file to use these functions in other scripts.
- '''
- '''This bit will cause the output of the script to be written to a file instead of to the console.
- this for some reason also seems to dramatically improve script runspeed.'''
- import sys
- sys.stdout = open('DNSmap.txt', 'w')
- def IP():
- '''This funtions retruns the current systems IP address.'''
- import socket
- return socket.gethostbyname(socket.gethostname())
- def nslookup(IP):
- '''Function that will determine a systems hostname when supplied with an IP address'''
- import socket
- name = socket.gethostbyaddr(IP)
- return name[0]
- def get_range(IP):
- return ".".join(IP.split(".")[0:3])
- if __name__ == "__main__":
- print('Current Host\'s Network Information:')
- print('\n')
- print('IP address: ' + IP())
- print('Hostname: ' + nslookup(IP()))
- print('\n')
- print('This hosts Neighbors include:')
- print('\n')
- ipRange = []
- for i in range(1, 254):
- ipRange.append(get_range(IP()) + '.' + str(i)) # <-- put your IP range here in the first set of ' '
- for e in ipRange:
- try:
- print(e + ', ' + nslookup(e))
- except:
- print(e + ', Host Unavailable')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement