pythonpython-3.xpython-sockets

TypeError: str, bytes or bytearray expected, not list


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.


Solution

  • Change

    check(ips, "80) 
    

    for

    for ip in ips: 
        check(ip, "80) 
    

    link.connect expected a unique ip and you're passing a list of ips.