Pinging a machine from python

Prasanth prasanths89 at
Tue Jul 22 03:50:58 CEST 2008

On May 26, 5:21 am, Zerge <zerg... at> wrote:
> On May 25, 11:13 am, Prasanth <prasanth... at> wrote:
> > 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 perl> or can you give me simple program.
> Import OS
> ip=
> 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 with 32 bytes of data:\r\n', '\r\n',
'Request timed out.\r\n', '\r\n', 'Ping statistics for\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.


More information about the Python-list mailing list