06-09-2008
|
#1
|
|
Python ile Port Tarama
Tanımlanan IP Adresine Göre Port Tarama Yapan Bir Script.

KOD :
-------------------------------------------------
# -*- coding:cp1254 -*-
#!/usr/bin/python
import socket as sk
import socket
import sys
import threading, Queue
import os
MAX_THREADS = 50
class Scanner(threading.Thread):
def __init__(self, inq, outq):
threading.Thread.__init__(self)
self.setDaemon(1)
# queues for (host, port)
self.inq = inq
self.outq = outq
def run(self):
while 1:
host, port = self.inq.get()
sd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sd.connect((host, port))
except socket.error:
self.outq.put((host, port, ’KAPALI’))
else:
self.outq.put((host, port, ’ACIK’))
sd.close()
def scan(host, start, stop, nthreads=MAX_THREADS):
toscan = Queue.Queue()
scanned = Queue.Queue()
scanners = [Scanner(toscan, scanned) for i in range(nthreads)]
for scanner in scanners:
scanner.start()
hostports = [(host, port) for port in xrange(start, stop+1)]
for hostport in hostports:
toscan.put(hostport)
results = {}
for host, port in hostports:
while (host, port) not in results:
nhost, nport, nstatus = scanned.get()
results[(nhost, nport)] = nstatus
status = results[(host, port)]
print ’%s:%d %s’ % (host, port, status)
# Taranacak Portların Bilgisi Kullanıcıdan Alınıyor
Baslangic_Port = int( raw_input("Taramaya Baslanacak Portu Giriniz: "))
Bitis_Port = int( raw_input("Taramanin Bitecegi Portu Giriniz: "))
# Port Taraması Yapılacak IP Adresini Kullanıcıdan Alınıyor
host = raw_input("Port Taramasi Yapilacak IP Adresini Giriniz: ")
if __name__ == ’__main__’:
scan(’%s’ %(host), Baslangic_Port, Bitis_Port)
print ""
raw_input(’Programdan cikmak icin "Enter" tusuna basin’)
|
|
|