473,287 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Pinging a machine from python

I tried pinging a machine from python using socket programming but
could not do it. Is there any module which we can use to ping the
machine < like net::ping in perlor can you give me simple program.
Jun 27 '08 #1
3 1662
[ Prasanth <pr*********@gmail.com]
I tried pinging a machine from python using socket programming but
could not do it. Is there any module which we can use to ping the
machine < like net::ping in perlor can you give me simple program.
At least on linux pinging requires raw sockets since there is no syscall for
sending ICMP packages. Raw sockets in turn require special privileges.
Therefore its best to use the os command _ping_, this limits the use of
priviledges to the required part and you don't have to deal with
priviledges (ping has suid bit set).

net::ping will most likely do the same.

--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
Jun 27 '08 #2
On May 25, 11:13 am, Prasanth <prasanth...@gmail.comwrote:
I tried pinging a machine from python using socket programming but
could not do it. Is there any module which we can use to ping the
machine < like net::ping in perlor can you give me simple program.
Import OS
ip=192.168.1.1
pingtext="ping "+ip+" -n 1"
pingresult=os.popen(pingtext).readlines()

"OS" gives you access to the command line of the operating system.
Jun 27 '08 #3
On May 26, 5:21*am, Zerge <zerg...@gmail.comwrote:
On May 25, 11:13 am, Prasanth <prasanth...@gmail.comwrote:
I tried pinging a machine from python using socket programming but
could not do it. Is there any module which we can use to ping the
machine < like net::ping in perlor can you give me simple program.

Import OS
ip=192.168.1.1
pingtext="ping "+ip+" -n 1"
pingresult=os.popen(pingtext).readlines()

"OS" gives you access to the command line of the operating system.
Thanks for the solution guys.

But the above program is giving the output as :

If we print pingresult it is giving the output as :

['\r\n', 'Pinging 0.168.1.1 with 32 bytes of data:\r\n', '\r\n',
'Request timed out.\r\n', '\r\n', 'Ping statistics for 0.168.1.1:\r
\n', ' Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),\r\n']

my requirement is

IP address and whether the machine is pinging or not. we should not
display the above output. However we can do it by using regular
expression or there is any other way. Please suggest.

Thanks,
Prasanth.
Jul 22 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Johnathan Doe | last post by:
I've been thinking about what the issues would be in compiling Python into native machine code, and since type information is important in Python, it seems possible that Python code can be...
4
by: M.N.A.Smadi | last post by:
hi; I need a simple script to run the ping command with some parameters and be able to read the return value of the ping function. Any pointers will be appreciated thanks m.smadi
2
by: dananrg | last post by:
I have Python 2.1 / PythonWin 2.1 installed on my machine because I need it for use with ESRI's ArcGIS Desktop software, but I want to play with a more recent version of Python. Is it safe to...
8
by: Thomas Dybdahl Ahle | last post by:
Hi, I've writing a python application in which I'd like to have a small "ping label", to always tell the current ping time to the server. It seems however that I have to be root to send those...
1
by: nethajireddy | last post by:
Hello techies In my office network all pc's are pinging and only two pc's let named as A and B, other are c,d.... if we ping A to B or B to A the result is "request time...
2
by: patelxxx | last post by:
Which Protocol do I use, when 'Pinging a server'? I am going to set up a Server status area on our companys website (sits on server A), the PERL coding will PING two other servers (server B & C)...
1
by: pavanG | last post by:
The following is the setup I have at home. The problem is I cannot ping Vista machine(192.168.2.5) from XP machine(192.168.2.2) So accessing it from Internet is Out of question My aim is to...
2
by: gzali | last post by:
i am facing the problem that my live ip server is not pinging on my system i am using wireless connection pionts and the server pinging on some systems not all including me.when i m pinging server...
1
by: sidd4one | last post by:
Hello, Hi experts when iam pinging from one of my system in the network. Its show iam "Unable to contact to ip adddress".This is message iam ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.