473,799 Members | 2,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1683
[ Prasanth <pr*********@gm ail.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...@gm ail.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.p open(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...@gm ail.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.p open(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
1702
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 compiled into native machine code (albeit with a lot of extra effort). For instance, type information is discovered when something is assigned to a variable or an anonymous piece of data is used in a program. Compiling Python bytecode into native...
4
2414
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
1988
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 install more than one version of Python / PythonWin on the same machine? I don't want the latest release to wipe out the old one.
8
4095
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 imcp packages, but I guess there must be a workaround since I can easily use the "ping" command as ordinary user. Do anybody know how to do this in python?
1
1708
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 out" If we ping to any other machines from thes two it's pinging, with ip also it's not pinging. any solution plz..... thanks in advance...
2
1440
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) to see their currently status every 5 mins. What Protocol do I use and why?
1
2382
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 host a website on the Vista machine(192.168.2.5). I have the XP machine(192.168.2.2) connected to the gateway router through WLAN. I connected the Vista machine to the Bridge(which is a Belkin router acting as a bridge) through LAN. I'm able...
2
2863
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 time out,when i m connection though vpn then error 721 come plz reply soon...
1
1486
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 getting.Can any one help in this record. Thank u sidd4one
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.