Skip to content

Instantly share code, notes, and snippets.

@bongbongco
Created March 29, 2019 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bongbongco/822b9e2dbac1907a1e252451702282cd to your computer and use it in GitHub Desktop.
Save bongbongco/822b9e2dbac1907a1e252451702282cd to your computer and use it in GitHub Desktop.
파이썬을 활용한 다량 호스트 ICMP 확인 스크립트(대상목록: target.txt, 결과목록: result.txt)
# works under Linux, Mac OS, Windows
import subprocess, platform
from time import sleep
def ping(host):
"""
Returns True if host responds to a ping request
"""
# Ping parameters as function of OS
ping_str = "-n 1" if platform.system().lower()=="windows" else "-c 1"
args = "ping " + " " + ping_str + " " + host
need_sh = False if platform.system().lower()=="windows" else True
# Ping
return subprocess.call(args, shell=need_sh) == 0
def main():
target_file_name="target.txt"
result_file_name="result.txt"
target_cursor = open(target_file_name, 'r')
write_cursor = open(result_file_name, 'a')
targets = target_cursor.readlines()
for target in targets:
target = target.rstrip('\n');
result = ping(target)
print(result)
write_cursor.write(
"{}\t{}\n".format(
target, result
)
)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment