Created
March 29, 2019 01:50
-
-
Save bongbongco/822b9e2dbac1907a1e252451702282cd to your computer and use it in GitHub Desktop.
파이썬을 활용한 다량 호스트 ICMP 확인 스크립트(대상목록: target.txt, 결과목록: result.txt)
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
# 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