2

I want to make a little tk app that continuous ping an ip and only show the MS, like, "10ms"

how could I do?

Bruno 'Shady'
  • 4,348
  • 13
  • 55
  • 73
  • Related: Ping a site in Python? http://stackoverflow.com/questions/316866/ping-a-site-in-python – jfs Mar 12 '10 at 09:37

2 Answers2

3

If you want to use Windows ping, you'll have to parse the output from the command line.

This is very specific, but should work:

import os
while(1):
    ping = os.popen('ping www.google.com -n 1')
    result = ping.readlines()
    msLine = result[-1].strip()
    print msLine.splot(' = ')[-1]
Mike Cialowicz
  • 9,892
  • 9
  • 47
  • 76
  • No problem. I suggest you print the result of each line, so you can see exactly what it's doing. Also: please accept the answer. Thanks! – Mike Cialowicz Mar 12 '10 at 04:52
0

To continuously ping an IP

os.system("ping -t 192.168.1.1")
YOU
  • 120,166
  • 34
  • 186
  • 219