def ip_and_time():
"""
get ip to ping from ip.txt
then return two list , each ip that ping successfully and the delay time of them
:return
""" time_list, ip_list = [], []
ip_txt = open('ip.txt', 'w')
ip_success, ip_fail = 0, 0
log_write = open('log.txt', 'a')
for ip in get_ip():
# 每个ip ping2次,等待时间为1s
cmd_return = os.popen('ping -n 2 -w 1 %s' % ip).read()
if 'ms' in cmd_return:
ip_list.append(ip.strip())
delay = cmd_return[cmd_return.rfind('='):]
delay_time = int(delay.replace('ms', '').replace('=', ''))
if delay_time <= 50:
delay_time = 150
time_list.append(delay_time)
ip_success += 1
elif 50 < int(delay_time) <= 100:
delay_time = 200
time_list.append(delay_time)
ip_success += 1
elif 100 < int(delay_time) <= 150:
delay_time = 250
time_list.append(delay_time)
ip_success += 1
elif 150 < int(delay_time) <= 200:
delay_time = 300
time_list.append(delay_time)
ip_success += 1
elif 200 < int(delay_time) <= 250:
delay_time = 350
time_list.append(delay_time)
ip_success += 1
elif 250 < int(delay_time) <= 300:
delay_time = 400
time_list.append(delay_time)
ip_success += 1
elif 300 < int(delay_time) <= 350:
delay_time = 450
time_list.append(delay_time)
ip_success += 1
elif 350 < int(delay_time) <= 400:
delay_time = 500
time_list.append(delay_time)
ip_success += 1
else:
delay_time = 550
time_list.append(delay_time)
ip_success += 1
elif len(cmd_return) <= 160:
# 当ping2次时窗口输出字符串长度小于160记为超时,否则记为传输过期
ip_list.append(ip.strip())
time_list.append(400)
ip_fail += 1
else:
ip_list.append(ip.strip())
time_list.append(400)
ip_fail += 1 log_write.close()
ip_txt.close()
return ip_list, time_list

ping ip的更多相关文章

  1. 批量Ping IP

    刚刚接触Python 想做点什么 听说Python 在网络方便很厉害 后来总结如下: 第一:发现公司都固定IP 每次新来同事都要猜一个没有人用的IP  很费劲 第二:我们公司有的IP可以上QQ 有的不 ...

  2. shell脚本和python脚本实现批量ping IP测试

    先建一个存放ip列表的txt文件: [root@yysslopenvpn01 ~]# cat hostip.txt 192.168.130.1 192.168.130.2 192.168.130.3 ...

  3. Shell学习笔记之shell脚本和python脚本实现批量ping IP测试

    0x00 将IP列表放到txt文件内 先建一个存放ip列表的txt文件: [root@yysslopenvpn01 ~]# cat hostip.txt 192.168.130.1 192.168.1 ...

  4. ping域名和ping IP时速度不同的原因

    不知道大家在ping的时候有没有遇到过这样的问题:当你ping一个域名的时候,ping结果返回得很慢,但是如果直接ping这个域名的ip,结果却快很多. 直接ping ip的时候,每两次发包之间没有明 ...

  5. linux ping IP地址与telnet 测试IP端口

    ping命令是不能够测试端口的,ping只是测试网络联接状况以及信息包发送和接收状况. 格式:ping IP地址或主机名 [-t] [-a] [-n count] [-l size] 参数含义:-t不 ...

  6. Linux 能PING IP 但不能PING 主机域名的解决方法 vim /etc/nsswitch.conf hosts: files dns wins

    Linux 能PING IP 但不能PING 主机域名的解决方法 转载 2013年12月25日 10:24:27 13749 . vi /etc/nsswitch.conf hosts: files ...

  7. 批量ping IP并检测IP延迟率和丢包率脚本

    脚本文件如下: #!/bin/bash #Author:Mr.Ding #Created Time:2018-08-26 07:23:44 #Name:ping.sh #Description: sh ...

  8. shell 编写脚本批量Ping IP

    服务器总是一下子买了很多的段的ip.通过绑定后,也不知道这些ip是否绑定成功,所以就写了一个shell脚本,把ip输好,批量ping一下,看是不是都能ping通. 脚本如下: 此外.还有一个ip文件, ...

  9. python实现批量ping IP,并将结果写入

    最近工作需要,写了一个Python小脚本,分享给大家,因为公司的IP用的差不多了,然后离职人员的IP有没有及时删除,导致没多少IP用了,所以做了一个python脚本跑了跑,清出来一堆ping不通的IP ...

  10. tomcat正常启动,但IP不能访问web。ping IP地址,一直超时。 用ipconfig命令修复TCP/IP的配置信息

    今天遇到一个好奇葩的问题  好吧是昨天遇到的一直没找到解决办法(`へ´) tomcat正常启动,但是通过IP不能访问web 用IP地址就是不行  (:′⌒`)  打不开 localhost就可以    ...

随机推荐

  1. CodeForces 719A Vitya in the Countryside (水题)

    题意:根据题目,给定一些数字,让你判断是上升还是下降. 析:注意只有0,15时特别注意一下,然后就是14 15 1 0注意一下就可以了. 代码如下: #pragma comment(linker, & ...

  2. A tutorial by example(转载)

    转自:http://mrbook.org/blog/tutorials/make/ Compiling your source code files can be tedious, specially ...

  3. 洛谷 - P1801 - 黑匣子 - 对顶堆

    这道题是提高+省选-的难度,做出来的话对数据结构题目的理解会增加很多. 可以使用一种叫做对顶堆的东西,对顶堆是在线维护第n小的logn的算法.大概的思路是,假如我们要找的是第n小,我们就维护一个大小为 ...

  4. 关于<?php exit;?>"的绕过问题

    在Moctf中看到一道题目: <?php show_source(__FILE__); $c="<?php exit;?>"; @$c.=$_POST['c']; ...

  5. Codeforces Round #324 (Div. 2)C. Marina and Vasya

    A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...

  6. Untiy检测各类设备输入

    轴需要单独设置 using UnityEngine; using System.Collections; using UnityEngine.UI; public class OutputKey : ...

  7. 笔记-JavaWeb学习之旅2

    数据库的基本概念 1.数据库:DataBase 简称 DB,用于存储和管理数据的仓库 特点: 1.持久化存储数据的,其实数据库就是一个文件系统, 2.方便存储和管理数据 3.使用了统一操作数据库 -- ...

  8. Qt文本读写之二:目录操作

    一.简介 QDir类用来访问目录结构及其内容,可以操作路径名.访问路径和文件相关信息以及操作底层的文件系统,还可以访问Qt的资源系统.Qt使用"/"作为通用的目录分隔符和URLs的 ...

  9. _bzoj1911 [Apio2010]特别行动队【斜率优化dp】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1911 裸的斜率优化dp. #include <cstdio> const int ...

  10. 洛谷 P2398 GCD SUM || uva11417,uva11426,uva11424,洛谷P1390,洛谷P2257,洛谷P2568

    https://www.luogu.org/problemnew/show/P2398 $原式=\sum_{k=1}^n(k\sum_{i=1}^n\sum_{j=1}^n[(i,j)=k])$ 方法 ...