This article mainly introduces examples of how to implement ping specified IP in Python. It has certain reference value. Now I share it with everyone. Friends in need can refer to it
Recommended Manual :Python basic introductory tutorial
Post code:
import os import sys iplist = list() ip = '192.168.1.11' # ip = '172.24.186.191' ip = 'www.baidu.com' backinfo = os.system('ping -c 1 -w 1 %s'%ip) # 实现pingIP地址的功能,-c1指发送报文一次,-w1指等待1秒 print 'backinfo' print backinfo print type(backinfo) if backinfo: print 'no' else: iplist.append(ip) print iplist
ip="192.168.1.11" The running results are as follows: ping fails
ip="172.24.186.191" The running results are as follows: pinging succeeds
## Recommended related articles: 1.
How to use Python scripts to ping Baidu and Google Recommended related videos:
1.
Little Turtle’s zero-based introduction to learning Python video tutorial2.
Python artificial intelligence full-stack engineer (Linux basics)
The above is the detailed content of Example of Python implementing ping specified IP. For more information, please follow other related articles on the PHP Chinese website!