0

#it suppose to pıng but ıt ıs not workıng
#do u know the reason why
#thanks

from subprocess import call, STDOUT

import time

class pinger(object):
	def __init__(self, ip="192.168.2.1"):
		self.ip=ip
		self.succes=False
		self.timer=time.sleep(0.0)
		self.cnt=0
	def wait(self):
		print "we are waiting. %s" % self.timer
		return self.timer
	def getwaiter(self):
		return self.wait
	def ping(self, i):#at he beggınıng ı dıd (ping(self, i)) andı gave me error
		self.ip=i
		while 1:
			self.cnt +=1
			s=call("ping -q 1 %s" % self.ip, shell=True, stdout=open("/dev/null", "w"), stderr=STDOUT)
			if s==0:
				self.succes=True
				print "pinging........ and alive hosts %s" % s, "COUNTER", self.cnt
			else:
				print "not able to: %s" % s
				self.succes=False
	def action(self):
		while self.succes:
			snc=self.ping(self.timer)
			if not snc:
				print "ok we are pinging..... %s " % snc
				self.succes=True
		else:
			print "unable to ping"
	def getip(self):
		return self.ip




P=pinger()
P.wait()
#P.action()
P.ping() #endless output
not able to: 2 # is the outout and ıt ıs not pingıng

Edited by rehber344: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by snippsat
0

Just wonder what you want to do.
If you just want to ping,this is an easy solution.

import os
os.system("ping " + '192.168.2.1') 

#Extern adress
import os
os.system("ping " + 'www.goolge.com')

Edited by snippsat: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.