Created
September 9, 2014 12:23
-
-
Save bot11/ebac67ef711afe025d4b to your computer and use it in GitHub Desktop.
Verify the remote port open
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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