if name == ‘main‘:
if len(sys.argv) != 3:
print("Usage: telnet [remote_ip | FQDN] [remote_port]")
exit()
if re.match(r"\d{1,5}",sys.argv[2]) is None:
print("remote port must be number")
exit()
hostname = sys.argv[1]
remote_port = int(sys.argv[2])
telnet_client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
telnet_client.connect((hostname,remote_port))
print(hostname+":"+str(remote_port)+" is open\n")
exit()
except Exception:
print(hostname+":"+str(remote_port)+" is closed\n")
exit()`
原文:https://blog.51cto.com/qinlouke/2529576