Port sweep with python
<p>Well im trying to do something really simpale but from some reason i just can't understand how to do it.</p>

<p>Im trying to write a simple port sweep
let's say i have a gateway address of 192.168.1.1 all i want to do is to create a for loop to run between 1 to 254 and test what ip address there are over the network </p>

<p>The for loop is really easy:</p>

<pre><code>for i in range(1,254,1):
</code></pre>

<p>I need that i will change everytime at 192.168.1.i</p>

<p>How can i do that?</p>

<p>There's a way of doing this in the standard library:</p>

<pre><code>&gt;&gt;&gt; import ipaddress
&gt;&gt;&gt; for addr in ipaddress.IPv4Network('192.168.1.0/24'):
...     print(addr)
192.168.1.0
192.168.1.1
192.168.1.2
192.168.1.3
#more addresses
192.168.1.254
192.168.1.255
</code></pre>

python for-loop networking ping