Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106772

Re: Python,ping,csv

From Jason Friedman <jsf80238@gmail.com>
Newsgroups comp.lang.python
Subject Re: Python,ping,csv
Date 2016-04-09 21:29 -0600
Message-ID <mailman.0.1460259273.424.python-list@python.org> (permalink)
References <o1JNy.43731$pt.31548@tornado.fastwebnet.it> <CANy1k1h392HiXq-onCAFj1zJkK0Z31AXeR6fEtnf7fZ-5fHkaQ@mail.gmail.com>

Show all headers | View raw


> for ping in range(1,254):
>     address = "10.24.59." + str(ping)
>     res = subprocess.call(['ping', '-c', '3', address])
>     if res == 0:
>         print ("ping to", address, "OK")
>     elif res == 2:
>         print ("no response from", address)
>     else:
>         print ("ping to", address, "failed!")

Note that with Python 3.3+ you can simplify slightly:

from ipaddress import IPv4Network
for address in IPv4Network('10.24.59.0/24').hosts():
    res = subprocess.call(['ping', '-c', '3', address])
    ...

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python,ping,csv Smith <smith@a-team.it> - 2016-04-08 09:25 +0200
  Re: Python,ping,csv Joel Goldstick <joel.goldstick@gmail.com> - 2016-04-08 05:18 -0400
  Re: Python,ping,csv Jason Friedman <jsf80238@gmail.com> - 2016-04-09 21:29 -0600
    Re: Python,ping,csv Smith <smith@a-team.it> - 2016-04-11 10:22 +0200
    Re: Python,ping,csv Smith <smith@a-team.it> - 2016-04-11 11:24 +0200
      Re: Python,ping,csv Jason Friedman <jsf80238@gmail.com> - 2016-04-11 19:17 -0600
      Re: Python,ping,csv Jason Friedman <jsf80238@gmail.com> - 2016-04-12 00:01 +0000

csiph-web