Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- from utils import timefunc
- class Scanner:
- def __init__(self, ip):
- self.ip = ip
- self.open_ports = [];
- #------------------------
- def __repr__(self):
- return 'Scanner: {}'.format(self.ip)
- def add_port(self, port):
- self.open_ports.append(port)
- def scan(self, lowerport, upperport):
- for port in range(lowerport, upperport + 1):
- if self.is_open(port):
- #print(port)
- self.add_port(port)
- def is_open(self, port):
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- result = s.connect_ex((self.ip, port))
- #print('Port {}: {}'.format(port, result)) # --PRINTS VERTICAL LIST OF PORTS--
- s.close()
- return result == 0
- def write(self, filepath):
- openport = map(str, self.open_ports) #--CONVERTS TO STRING--
- with open(filepath, 'w') as f:
- f.write('\n'.join(openport)) #--WRITES RESULT TO A FILE--
- #------------------------
- @timefunc
- def main():
- ip = '192.168.10.666'
- scanner = Scanner(ip)
- scanner.scan(1, 65535)
- scanner.write('./open_ports')
- print(scanner.open_ports)
- #------------------------
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment