-
-
Save trsqxyz/7822872 to your computer and use it in GitHub Desktop.
ping command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import shlex, subprocess | |
class Ping(): | |
def __init__(self): | |
self.hosts = {'Google': '173.194.38.82'} | |
def ping(self, check=[], count=1): | |
prm = len(self.hosts) | |
for host in self.hosts: | |
ip = self.hosts[host] | |
out, err = self.cmd('ping', '-n', '1', ip) | |
if not 'TTL' in out: | |
check.append(host) | |
else: | |
print '%d/%d: FINE!' % (count, prm) | |
count += 1 | |
if count == prm: | |
print '%d/%d: FINE!' % (count, prm) | |
opt = raw_input('everything is OK.\n opt: s') | |
self.show(opt) | |
return check | |
def cmd(self, *args): | |
cmds = [arg for arg in args] | |
cmd = " ".join(cmds) | |
args = shlex.split(cmd) | |
p = subprocess.Popen( | |
args, | |
stdout = subprocess.PIPE, | |
stderr = subprocess.PIPE | |
) | |
out, err = p.communicate() | |
return out, err | |
def show(self, cmd=''): | |
if cmd == 's': | |
for host in self.hosts: | |
print '%s: %s' % (host, self.hosts[host]) | |
raw_input('Return...') | |
if __name__ == '__main__': | |
check = Ping() | |
done = check.ping() | |
if done: | |
for d in done: | |
print '%s is (x_x)' % d | |
raw_input('\nCOPY?') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment