Skip navigation

Category Archives: Python

I have recently started to script in Python and created some easy tools which make life easier. Given Python is so high level, even if I a no programmer the logic can be undertood very easily. There are many examples on the net and eventually customising the code to your liking becomes easy.

I started with integrating tools I use everyday such as “nslookup” . This tool is simply an interactive nslookup utility, which asks you to insert the host name and the server name to issue an “all” query.

The source code can be found here –

# Import the module
import subprocess

# Ask the user for input
host = raw_input(“Enter a host to lookup: “)
server = raw_input(“Enter a server to query: “)

# Set up the nslookup command and direct the output to a pipe
p1 = subprocess.Popen([‘nslookup’, ‘-querytype=all’, host, server], stdout=subprocess.PIPE)

# Run the command
output = p1.communicate()[0]

print output

import sys
f = open(‘nslookup.txt’, ‘w’)
sys.stdout = f
print output

raw_input()

Another utility i required was a reverse DNS tool. The source code can be found here –

import socket

add = raw_input(“Enter IP to reverse lookup: “)
reversed_dns = socket.gethostbyaddr(add)
print reversed_dns

raw_input()

I created many others such as Ping and port scanning utilities but these two are the two i used most.

 

 

Advertisements