Jump to content
against_modern_football

python port scanner

Recommended Posts

Posted (edited)

Am facut un "port-scanner" cu threaduuri in Python. Daca aveti timp si chef sa va dati cu parerea mi-ar fi de mare ajutor.

import socket
import threading
import sys
import string
import os


class ThreadingScan(threading.Thread):
def __init__(self, target):
threading.Thread.__init__(self)
self.target=target


def run(self):

ping_parameter='ping '+self.target
result=os.popen(ping_parameter)
if (result):
with open('log.txt', 'a', encoding='utf-8') as log_file:
log_string=self.target+ ' is alive \n'
log_file.write(log_string)
print(self.target, ' is alive\n')
port_scan=ThreadingPortScan(self.target)
port_scan.start()


class ThreadingPortScan(threading.Thread):
def __init__(self, port_target):
threading.Thread.__init__(self)
self.port_target=port_target

def run(self):
target_ip=socket.gethostbyname(self.port_target)
print(target_ip)
print('starting port scanning')
for i in range(1024):

target_sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result=target_sock.connect_ex((target_ip, i))
if (result==0):
##log_file=open('log.txt', 'a', encoding='utf-8')
log_string=self.port_target+' has port '+ str(i)+ ' opened \n'
print(log_string)
#log_file.write(log_string)
#log_file.close()
target_sock.close()



if __name__=='__main__':
with open('host_file.txt', 'r', encoding='utf-8') as host_file:
hosts=host_file.read()
host_list=str.split(hosts)
for i in range(len(host_list)):
scanning=ThreadingScan(host_list[i])
scanning.start()







Later edit: aveti nevoie de un fisier host_file.txt in care sa fie hosturile pe care vreti sa le scanati

Edited by against_modern_football
  • Upvote 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...