Reputation: 33
Just trying to make my code more efficient!
ip = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
err = []
for address in ip:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((address, 9999))
if result != 0:
err.extend(address)
print(err)
this is the output I receive:
['1', '.', '1', '.', '1', '.', '1', '2', '.', '2', '.', '2', '.', '2', '3', '.', '3', '.', '3', '.', '3']
if I run typecast to be either a float or int, there are errors thrown. I just need each ip address inserted into a list so I can print them out looking like:
1.1.1.1
Upvotes: 0
Views: 50
Reputation: 191983
Use err.append
to add strings rather than extend, which iterates the string to characters
Upvotes: 1