#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

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')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.