Как я могу заставить мой сканер портов работать - PullRequest
0 голосов
/ 13 мая 2018

Я пытаюсь сделать сканер портов, который ищет порт, который вводится по всем нечетным IP-адресам в диапазоне 10-255.

Мой текущий код не работает, и я получаюэта ошибка;

error  str, bytes or bytearray expected, not int

Я думал, s.connect((int(ipaddress.ip_address(my_net[i])), port)) это исправит, но это не так.

Я что-то упустил?

Мой текущий код указан ниже:

import socket
import ipaddress
import subprocess
import sys
from datetime import datetime
#define the subnet to scan
subnet=input("which subnet are you scanning, please enter in x.x.x ")

my_net =[]
count =0
for i in range(11,255):  
    if i%2!=0:
        my_net.insert(count,(subnet+"." +str(i)))

print("Your selected network is " , subnet , "below are the usable Ip addresses")
#the user is to select the port that will be scanned as a part of the test
port = input("Enter the number of the port you would like to scan ")
# Print a banner with information on which host we are about to scan
print ("-" * 60)
print ("Please wait, scanning network" , subnet ,".0/24")
print ("-" * 60)
#check time now#
t1 = datetime.now()
#output. Confirm if the port is open or closed

for i in range(len(my_net)):
        try:
            socket.setdefaulttimeout (2)
            s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((int(ipaddress.ip_address(my_net[i])), port))
            banner=s.recv(1024)
            print(banner)
        except Exception as e:
            print("error " , e)

# Checking the time again
t2 = datetime.now()
# Calculates the difference of time, to see how long it took to run the script
total =  t2 - t1
print ('Scanning Completed in: ', total)

1 Ответ

0 голосов
/ 13 мая 2018

Я думаю, вы обнаружите, что IP-адрес должен быть строкой. Например, «127.0.0.1» не int, а порт - int.

...