PING:
import os
ip=1.1.1.1
o=os.system("ping "+ip)
time.sleep(10)
print(o)
if res == 0:
print(ip,"is active")
Telnet:
tn = telnetlib.Telnet(IP)
tn.write(command+"\r\n")
f=open(filename,w)
while True:
response = tn.read_until("\n")
f.write(response)
Here, In between IP goes down. During that time i need to ping that IP & whenever it comes up i need to start collecting logs again. How can i do this ?
Actually, I need to collect logs through telnet (which is indefinite). I could able to do it. During this process, IP from which i'm collecting logs goes down. So, I need to track on this IP (Ping). Whenever IP comes up again, I've to start collecting the logs again. It would be great, if you can help me on this.
I found the solution:
tn=telnetlib.Telnet(IP)
tn.write(command+"\r\n")
f=open(filename,w)
while (os.system("ping -n 1 IP") == 0):
response = tn.read_until("\n")
f.write(response)
else:
call some module for telnetting again/goto
But, here is it possible to hide the console when we use (os.system(ping)). I know it can be done through subprocess. But since os.system is a one liner & very easy to verifY the result also.