1import socket
2 import sys
3 import os
4 #grab the banner
5 def grab_banner(ip_address,port):
6 try:
7 s=socket.socket()
8 s.connect((ip_address,port))
9 banner = s.recv(1024)
10 print (ip_address + ':' + banner )
11 except:
12 return
13 def checkVulns(banner):
14 if len(sys.argv) >=2:
15 filename = sys.argv[1]
16 for line in filename.readlines():
17 line = line.strip('\n')
18 if banner in line:
19 print ("%s is vulnerable" %banner)
20 else:
21 print ("%s is not vulnerable")
22 def main():
23 portList = [21,22,25,80,110]
24 for x in range(0,255):
25 for port in portList:
26 ip_address = '192.168.0.' + str(x)
27 grab_banner(ip_address,port)
28 if __name__ == '__main__':
29 main()
1import socket
2
3ip = input('IP Address: ')
4starting_port = ('Starting port: ')
5ending_port = ('Ending port: ')
6
7for port in range(starting_port, ending_port):
8 try:
9 print(f'Getting service information for port: {port}')
10 s = socket.socket()
11 s.connect((ip, port))
12 banner = s.recv(1024)
13 print(f"{ip}: {banner}")
14 except:
15 print(f'Cannot connect to port: {port}')