Created
March 20, 2018 19:50
-
-
Save brianbruggeman/92d50ac113ff951e9fb3ae5bb4a90027 to your computer and use it in GitHub Desktop.
Checks for availability of an ip and port in python using click
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
#!/usr/bin/env python | |
import socket | |
import click | |
@click.command() | |
@click.argument('ip') | |
@click.argument('ports', nargs=-1, type=int) | |
def check(ip, ports): | |
"""Check ip and port""" | |
for port in ports: | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
result = sock.connect_ex((ip, port)) | |
status = 'open' if result == 0 else 'closed' | |
print(f'Port {port} is {status} at {ip}') | |
check() |
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
click |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment