I'm trying to make a banner grabber that prompts a user for their ip address and port. What I have so far is:
(Here's a pic of the bannergrabber code if the site shows it weird https://i.stack.imgur.com/PqpJf.jpg and a pic of the hexdump code https://i.stack.imgur.com/Q56gI.jpg)
import socket
import sys
def bannergrabber(ip_address,port):
try:
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip_address,port))
banner = s.recv(4096)
print ip_address + ":" + banner
except
return
Pretty obvious I'm not sure what I'm doing. I want to establish a TCP connection with the IP and port which is why I have socket.SOCK_STREAM
in there. After that I'm printing the output with this hexdump
function:
def myhexdump(src, length=16)
result=[]
for i in range(0, len(src), length):
substring = src[i:i+length]
result.append("%04x" %i)
hex = "".join("%X" % ord(c) for c in substring)
result.append("%-*s %s\n" %(length*3, hex, substring))
print b".join(result)