1

I would like to do something like (Windows 7/10 underneath)

for i in range (1,254):
    ! ping -n 1 192.168.2.+str(i)

Reason behind: want to quickly scan my WLAN to see where responding IP addresses are (finding a repeater).

Is there a python package allowing for this directly and how do I pass a parameter to the bang command in the above (pseudo-) example?

OK, I found this working, but not elegant:

import os
for i in range (1,100):
    n= "192.168.2."+str(i)
    ! ping -n 1 $n
Krischu
  • 1,024
  • 2
  • 15
  • 35

1 Answers1

2

Well, you essentially answered the question yourself. You don't need to cast to string:

for i in range (1, 100):
    ! ping -n 1 192.168.2.$i

And for future reference, you can execute python code in the magic ! command using curly braces. This is equivalent to the above:

for i in range (1, 100):
    ! ping -n 1 192.168.2.{i}

for i in range (1, 100):
    ! ping -n 1 192.168.2.{str(i)}

And obiously you can also do stuff like e.g.:

for i in range (1, 8):
    ! ping -n 1 192.168.2.{pow(2, i) - 1}
j4nw
  • 2,227
  • 11
  • 26