Home >Backend Development >Python Tutorial >Example of Python implementing ping specified IP

Example of Python implementing ping specified IP

不言
不言Original
2018-06-04 10:54:5524330browse

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 ManualPython 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn