Python | Subnet Ping

This script will ping and display status of all hosts in a subnet we provide.

import subprocess
import ipaddress
from subprocess import Popen, PIPE
subnet = input("Please enter the network: ")
network = ipaddress.ip_network(subnet)
for i in network.hosts():
    i=str(i)
    toping = subprocess.Popen(['ping', '-c', '3', i], stdout=PIPE)
    output = toping.communicate()[0]
    hostalive = toping.returncode
    if hostalive == 0:
        print(i,'is ' + '\033[92m' + 'reachable' + '\033[0m')
    else:
        print(i,'is ' + '\033[91m' + 'unreachable' + '\033[0m')

That's what the script works:

drm@STENGE % python3 ping-subnet.py
Please enter the network: 192.168.0.0/29
192.168.0.1 is reachable
192.168.0.2 is unreachable
192.168.0.3 is reachable
192.168.0.4 is reachable
192.168.0.5 is reachable
192.168.0.6 is reachable
drm@STENGE % 


135 views0 comments

Recent Posts

See All

How to encrypt and decrypt files in Python When you need to encrypt text, it is important to understand the different options you have. There are different ways to encrypt text, like using a password,

### 👽⚠️ 𝗧𝗵𝗶𝘀 𝘀𝗰𝗿𝗶𝗽𝘁 𝗶𝘀 𝗷𝘂𝘀𝘁 𝘁𝗵𝗲 𝘁𝗼𝗼𝗹 𝗳𝗼𝗿 𝗲𝗱𝘂𝗰𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗮𝗻𝗱 𝘁𝗲𝘀𝘁𝗶𝗻𝗴 𝗽𝘂𝗿𝗽𝗼𝘀𝗲𝘀 ⚠️👽 ### Descriptions: This is script for spamming the message from Wh

XML (Extensible Markup Language) is a markup language similar to HTML, but without predefined tags to use. Instead, you define your own tags designed specifically for your needs. This is a powerful wa