Skip to content

Instantly share code, notes, and snippets.

@codeif
Created April 11, 2017 03:50
Show Gist options
  • Save codeif/b4c2d37102c863fb63815870e8d643b4 to your computer and use it in GitHub Desktop.
Save codeif/b4c2d37102c863fb63815870e8d643b4 to your computer and use it in GitHub Desktop.
check socket port
# -*- 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