Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a network 192.168.1.0 with two computer. Raspberry Pi with IP = 192.168.1.7 and laptop with IP = 192.168.1.4 I want to write code using python to ping laptop from raspberry pi. How can I make it?
I try to write this, but it failed.
Python
import subprocess as sp
ip = "192.168.1.4"
status, result = sp.getstatusoutput("ping -c1 -w2" + ip)
if(status ==0):
    print("UP")
else:
    print("DOWN")

How can I fix it?
Posted
Updated 7-Apr-20 3:56am
v2

The ping example is shown here: http://stackoverflow.com/questions/316866/ping-a-site-in-python[^].

You only need to replace domain names with your IP address strings, such as "192.168.1.7" "192.168.1.4".

—SA
 
Share this answer
 
Comments
Member 10390715 13-Nov-14 3:12am    
thanks you, I try it
Sergey Alexandrovich Kryukov 13-Nov-14 11:33am    
Please do. If you don't mind, notify us if it worked out.
—SA
you just only need to make a space after -w2 because since the ip address is string attached with -w2 that's why is not working to you :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900