Example of Python implementing ping specified IP

不言
Release: 2019-11-30 09:41:45
Original
24296 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template