Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ping Sweep help
#6
Since Python 3.3 there is a nice module in the stdlib for ipaddress.

import ipaddress
start_ip = ipaddress.ip_address('192.168.0.1')
for i in range(254):
   print(start_ip + i)

21.28. ipaddress — IPv4/IPv6 manipulation library

If you want to get a range for a whole network, you should use following:
ip_network_24 = ipaddress.ip_network('192.168.0.0/24') # Netmask = 255.255.255.0
ip_network_16 = ipaddress.ip_network('192.168.0.0/16') # Netmask = 255.255.0.0

print('Whole 192.168.0.0/24 network:')
for ip in ip_network_24.hosts():
   print(ip)
# Network Address and Braodcast Address are excluded.
# 254 hosts

print('Whole 192.168.0.0/16 network:')
for ip in ip_network_16.hosts():
   print(ip)
# 65534 hosts
This module saves you against string manipulation. All important logic is inside the module and has a good abstraction. This saves brain-time.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Ping Sweep help - by The501stOfNoobPy - Jun-25-2017, 02:33 PM
RE: Ping Sweep help - by Bass - Jun-25-2017, 02:44 PM
RE: Ping Sweep help - by The501stOfNoobPy - Jun-25-2017, 03:12 PM
RE: Ping Sweep help - by Bass - Jun-25-2017, 05:27 PM
RE: Ping Sweep help - by Larz60+ - Jun-25-2017, 06:17 PM
RE: Ping Sweep help - by DeaD_EyE - Jun-26-2017, 10:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some guidance on a script to ping a list of ip's cubangt 11 2,026 Aug-10-2023, 02:39 PM
Last Post: snippsat
  non-stop ping script kucingkembar 1 1,401 Aug-23-2022, 06:29 AM
Last Post: menator01
  Win32\ping.exe windows pops up -very annoying... tester_V 9 3,360 Aug-12-2021, 06:54 AM
Last Post: tester_V
  Looking for discord bot to make loop ping for address ip tinkode 0 1,860 Jul-26-2021, 03:51 PM
Last Post: tinkode
  Ping command using python 3.6.5 Martin2998 6 17,610 Apr-19-2021, 06:24 PM
Last Post: blazejwiecha
  GPIO high if network IP has good ping duckredbeard 3 2,410 Oct-12-2020, 10:41 PM
Last Post: bowlofred
  Create a program that PING a list of IPs skaailet 7 6,564 Mar-26-2020, 10:46 PM
Last Post: snippsat
  ping with output jacklee26 1 5,019 Nov-28-2019, 01:01 PM
Last Post: Axel_Erfurt
  PING PONG GAME akea 0 5,739 May-08-2019, 04:30 PM
Last Post: akea
  Ping Code Problem MTom5 1 2,795 Sep-04-2018, 09:58 PM
Last Post: MTom5

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020