python
The following is a collection of personal study python research to determine ip connectivity methods. There may be ways to work around the shortcomings, so feel free to correct any errors.
Method 1
import os return1=('ping -n 2 -w 1 172.21.1.183') print return1
Disadvantage: cmd pop-up window
Method II
#-*- coding: utf-8 -*- import subprocess import re p = ([" ", '172.21.183.183'],stdin = ,stdout = ,stderr = ,shell = True) out = () print out regex = ("Minimum = (\d+)ms, Maximum = (\d+)ms, Average = (\d+)ms", ) print (out)
Disadvantage: Default ping 4 times No way to control the number of pings yet.
Method III
from subprocess import call result = call("ping 172.21.4.20 -n 1",shell=True) print result
Cons, doesn't seem very reliable
Method 4 This way should be called under linux, haven't tried it.
import os,sys,re import subprocess p = (["ping -c 1 -w 1 172.21.183.183"],stdout=,stderr=,shell=True) out=() err=() regex=('100% packet loss') print out
The above summary of this python implementation of the method to determine ip connectivity is all that I have shared with you, I hope to give you a reference, and I hope you support me more.