【问题标题】:Scan range of IP with ping command and give specific result使用 ping 命令扫描 IP 范围并给出具体结果
【发布时间】:2017-02-12 14:58:00
【问题描述】:

你好,我想在 python 上创建一个 ping 脚本,它将 ping 3 个 ips 并只在服务器处于活动状态时给我结果我想给我丢包并在 ms 时间小于 100 时生成。我没有pythong专家技能

【问题讨论】:

    标签: python windows cmd ip ping


    【解决方案1】:

    只需用 List 更改主机名并在另一个 StackOverflow 线程中给出的代码中提供 ip 地址

    Check out this

    示例代码

    import subprocess
    hosts = ['link1','link2','link3']
    for host in hosts:
        result = subprocess.check_output("ping google.com")
        print result
        # do some process on result 
    

    【讨论】:

    • 时间和丢包情况如何?执行该代码后会列出吗?因为我希望它给出包遇到的损失结果和毫秒时间
    • 有没有办法在文本文件中打印结果值?
    • 看到你必须对结果进行处理并提取你正在寻找的任何信息。你可以使用 Regex docs.python.org/2/library/re.html 。如果您想进行持续监控,那么最好使用线程。
    猜你喜欢
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-17
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    相关资源
    最近更新 更多