Created
July 20, 2015 19:51
-
-
Save HarryCoops/0b5ea0801b6021e30f74 to your computer and use it in GitHub Desktop.
Host discovery program in python. Usage: pingsweep.py base_ip range,
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
import os | |
import sys | |
import subprocess | |
def scan(base, ceiling): | |
base_suff = int(base.split('.')[-1]) | |
for i in range(base_suff, ceiling+1): | |
hostname = '.'.join(base.split('.')[:-1] + [str(i),]) | |
try: | |
with open('/dev/null') as f: | |
response = subprocess.check_call(['ping', '-c1', '-W2',hostname], stdout=f) | |
except subprocess.CalledProcessError: | |
print(hostname + ': ', 'DOWN') | |
else: | |
print(hostname + ': ', 'UP') | |
def main(): | |
base = sys.argv[1] | |
ceiling = int(sys.argv[2]) | |
scan(base, ceiling) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment