Networking - Multiple Ping Script in Python - Stack Overflow
Networking - Multiple Ping Script in Python - Stack Overflow
Networking - Multiple Ping Script in Python - Stack Overflow
2 you
By using our site, Tryacknowledge
Scapy. – kichik
thatAug
you23 '12 at
have read and understand our Cookie Policy, Privacy Policy, and our
23:15
Terms of Service.
Here is an example
https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python 1/7
12/27/2018 networking - Multiple ping script in Python - Stack Overflow
github.com/lbaby/javalearn/blob/maste
r/shell/ppe.py – lbaby Feb 13 '13 at
12:50
8 Answers
https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python 2/7
12/27/2018 networking - Multiple ping script in Python - Stack Overflow
This script:
import subprocess
9 import os
with open(os.devnull, "wb") as limbo:
for n in xrange(1, 10):
ip="192.168.0.{0}".for
result=subprocess.Pope
stdout=limbo,
if result:
print ip, "ina
else:
print ip, "act
192.168.0.1 active
192.168.0.2 active
192.168.0.3 inactive
192.168.0.4 inactive
192.168.0.5 inactive
192.168.0.6 inactive
192.168.0.7 active
192.168.0.8 inactive
192.168.0.9 inactive
p=Popen( ... )
output=p.communicate()
result=p.wait()
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
answered Aug 23 '12 at 23:15
Terms of Service.
hochl
https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python 3/7
12/27/2018 networking - Multiple ping script in Python - Stack Overflow
8,929 7 33 67
import subprocess
import os
with open(os.devnull, "wb") as limbo:
for n in xrange(200, 240):
ip="10.2.7.{0}".format
result=subprocess.Pope
stdout=limbo,
if result:
print ip, "ina
else:
print ip, "act
import ipaddress
from subprocess import Popen, PIPE
net4 = ipaddress.ip_network('192.168.2
for x in net4.hosts():
x = str(x)
hostup = Popen(["ping", "-c1", x],
output = hostup.communicate()[0]
val1 = hostup.returncode
if val1 == 0:
print(x, "is pinging")
else:
print(x, "is not responding")
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python 4/7
12/27/2018 networking - Multiple ping script in Python - Stack Overflow
p = {} # ip -> process
for n in range(1, 100): # start ping p
ip = "127.0.0.%d" % n
p[ip] = Popen(['ping', '-n', '-w5'
#NOTE: you could set stderr=subpro
while p:
for ip, proc in p.items():
if proc.poll() is not None: #
del p[ip] # remove from th
if proc.returncode == 0:
print('%s active' % ip
elif proc.returncode == 1:
print('%s no response'
else:
print('%s error' % ip)
break
import subprocess
import os
'''
0 servers.txt contains ip address in fol
192.168.1.1
192.168.1.2
'''
with open('servers.txt', 'r') as f
for ip in f:
result=subprocess.Popen(["
stderr=f).wait()
if result:
print(ip, "inactive")
else:
print(ip, "active")
d J 12 '16 t 7 29
https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python 5/7
12/27/2018 networking - Multiple ping script in Python - Stack Overflow
answered Jan 12 '16 at 7:29
Razi Ahmed
1
For example:
import subprocess
import ipaddress
subnet = ipaddress.ip_network('192.168
for i in subnet.hosts():
i = str(i)
subprocess.call(["ping", "-c1", "-
#!/usr/bin/env python
import subprocess
import ipaddress
alive = []
subnet = ipaddress.ip_network('192.168
for i in subnet.hosts():
i = str(i)
retval = subprocess.call(["ping",
if retval == 0:
alive.append(i)
for ip in alive:
print(ip + " is alive")
192.168.0.1 is alive
192.168.0.2 is alive
192.168.1.1 is alive
192.168.1.246 is alive
https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python 6/7
12/27/2018 networking - Multiple ping script in Python - Stack Overflow
51 5
import subprocess,os,threading,time
from queue import Queue
lock=threading.Lock()
-1 _start=time.time()
def check(n):
with open(os.devnull, "wb") as lim
ip="192.168.21.{0}".fo
result=subprocess.Pope
ip],stdout=limbo, stderr=limbo).wait()
with lock:
if not result:
print (ip, "ac
else:
pass
def threader():
while True:
worker=q.get()
check(worker)
q.task_done()
q=Queue()
for x in range(255):
t=threading.Thread(target=threader
t.daemon=True
t.start()
for worker in range(1,255):
q.put(worker)
q.join()
print("Process completed in: ",time.ti
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python 7/7