Jump to content
gorski

IP and port scanner in python

Recommended Posts

Posted

#!/usr/bin/env python

"""
Scanner pentru orice cu o adresa IP si care nu are parola && user
(sper sa-i fie de folos cuiva)
"""

import sys
import socket
import struct

raw_ip = raw_input("Enter the starting IP address: ")
port = raw_input("Enter the port you want to scan: ")
ip_number = raw_input("Enter the numer of IPs you want to scan: ")

print "Working..."

ip2int = lambda ipstr: struct.unpack('!I', socket.inet_aton(ipstr))[0]
int2ip = lambda n: socket.inet_ntoa(struct.pack('!I', n))

ip_number = int(ip_number)
inted_ip = ip2int(raw_ip)

i = 1

while i <= ip_number:
if i == ip_number:
print 'Job Done.'
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((raw_ip, int(port)))
if result == 0:
f = open('list.txt', 'w')
f.write(int2ip(inted_ip) + ':' + port + '\n')
else:
print "Nothing found."
inted_ip+=i
sock.close()
except KeyboardInterrupt:
print "Exiting..."
sys.exit()
except socket.error:
print "Could not connect to the server. Exiting..."
sys.exit()
i += 1;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...