Skip to content

Instantly share code, notes, and snippets.

@bot11
Created September 9, 2014 12:23
Show Gist options
  • Save bot11/ebac67ef711afe025d4b to your computer and use it in GitHub Desktop.
Save bot11/ebac67ef711afe025d4b to your computer and use it in GitHub Desktop.
Verify the remote port open
class Connect:
def __init__(self, ip, port):
self.ip = ip
self.port = port
def verify(self):
import socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((self.ip, self.port))
if client_socket.send('\n') == 1:
return True
else:
return False
except socket.error:
return False
finally:
client_socket.close()
if __name__ == "__main__":
f = open('ip_ports', 'r')
for line in f.readlines():
line.strip()
print line
(ip, port) = line.split()
port = int(port)
connection = Connect(ip, port)
if not connection.verify():
print ("%s:%d closed" % (ip, port))
else:
print ("%s:%d open" % (ip, port))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment