Created
April 11, 2017 03:50
-
-
Save codeif/b4c2d37102c863fb63815870e8d643b4 to your computer and use it in GitHub Desktop.
check socket port
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import socket; | |
from contextlib import closing | |
socket.setdefaulttimeout(0.5) | |
import socket | |
from contextlib import closing | |
def check_socket(host, port): | |
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: | |
result = sock.connect_ex((host, port)) | |
print(host, result) | |
if result == 0: | |
print('*' * 30, host) | |
for i in range(1, 2): | |
for j in range(180, 200): | |
ip = '192.168.{}.{}'.format(i, j) | |
check_socket(ip, 22) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment