So I am trying to pull some IP's from a text file and using that list in the socket connection. My issue is I keep getting the following error:
TypeError: str, bytes or bytearray expected, not list
Here is the code im using:
import socket
ips = open('list.txt', 'r').readlines()
def displayType(sec_type):
switcher = {
0: "1",
1: "2",
2: "3"
}
print(' type: ' + str(sec_type) + ' (' + switcher.get(sec_type,"Not defined by IETF") +')' )
try:
def check(ip,port):
link = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
link.connect((ip,int(port)))
link_ver = link.recv(12)
print(link_ver)
link.send(link_ver)
nb_sec_types = ord(link.recv(1))
print("types: " + str(nb_sec_types))
check(ips,"80")
If anyone has an idea on how to use the ip's from the list that would be great.
ipsIs a list. When you calllink.connect, you end up passing alistas an argument, but it says thatlink.connectexpects a string instead. You can fix that by iterating through your list ofips, for example:for ip in ips: check(ip, "80)