Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.

Commit 713fc74

Browse files
authored
Network Scripts directory added (#611)
Added pingsweep-network-scanner in Network_Scripts/. Signed-off-by: Jayaditya Dev <[email protected]>
1 parent a561a83 commit 713fc74

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Ping Sweep Network Scanner
2+
3+
## Table of Contents
4+
5+
- [Overview](#overview)
6+
- [Features](#features)
7+
- [Usage](#usage)
8+
- [Example](#example)
9+
10+
## Overview
11+
12+
This Python script allows you to perform a ping sweep on a range of IP addresses within a specified subnet to identify live hosts. It supports both Windows and Unix-like systems for the ping command.
13+
14+
## Features
15+
16+
- Scan a range of IP addresses within a subnet.
17+
- Detect live hosts within the specified range.
18+
- Cross-platform compatibility (Windows and Unix-like systems).
19+
20+
## Usage
21+
22+
1. Run the program
23+
24+
* For Windows (Powershell/CMD):
25+
26+
```
27+
python main.py
28+
```
29+
30+
* For Linux (bash/zsh/unix):
31+
32+
```bash
33+
sudo python3 main.py
34+
```
35+
36+
`Root privilege is required for linux users, as modern kernels of linux don't allow pinging without root privilege.`
37+
38+
2. Follow the on-screen instructions to provide the following information:
39+
40+
* Subnet IP (e.g., 192.168.0)
41+
* Starting IP range
42+
* Ending IP range
43+
44+
## Example
45+
46+
```
47+
Enter the SUBNET IP: 192.168.1
48+
Enter Starting Range: 1
49+
Enter Ending Range: 10
50+
```
51+
The script will scan the hosts ranging from IP Address: 192.168.1.1 to 192.168.1.10.
52+
53+
```
54+
Scanning completed in 0:00:13.741418
55+
56+
Live Hosts:
57+
192.168.1.1 --> Live
58+
192.168.1.2 --> Live
59+
192.168.1.5 --> Live
60+
192.168.1.7 --> Live
61+
192.168.1.9 --> Live
62+
```
63+
64+
---
65+
66+
`The efficiency of the program solely depends on factors such as network traffic and connectivity of devices to the router/dhcp server. Also, in some cases, the program skips some live hosts, even though they're up due to delay in responding to the ping command within the time slot.`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import platform
2+
from datetime import datetime
3+
import subprocess
4+
5+
6+
def instructions():
7+
print("""
8+
1. Enter an IP range for the ping sweep.
9+
2. Enter the range to start ping from.
10+
3. Enter the range to end ping at.
11+
12+
Example: -192.168.0
13+
-2
14+
-8
15+
Script will scan from 192.168.0.2 to 192.168.0.8 \n""")
16+
17+
18+
def network_info():
19+
subnet_ip = input('Enter the SUBNET IP: ')
20+
first_host = int(input('Enter Starting Range: '))
21+
last_host = int(input('Enter Ending Range: ')) + 1
22+
return subnet_ip, first_host, last_host
23+
24+
25+
def network_scan():
26+
subnet_ip, first_host, last_host = network_info()
27+
time1 = datetime.now()
28+
live_hosts = []
29+
30+
for ip in range(first_host, last_host):
31+
addr = f"{subnet_ip}.{ip}"
32+
command = f"ping -n 1 -w 2500 {addr}" if platform.system() == 'Windows' else f"ping -c 1 -W 2 {addr}"
33+
response = subprocess.run(command, capture_output=True, text=True, shell=True)
34+
35+
if "TTL" in response.stdout or "ttl" in response.stdout:
36+
live_hosts.append((addr, 'Live'))
37+
38+
time2 = datetime.now()
39+
total = time2 - time1
40+
print("\nScanning completed in", total)
41+
42+
return live_hosts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import functions
2+
3+
4+
def main():
5+
live_hosts = functions.network_scan()
6+
if live_hosts:
7+
print("\nLive Hosts:")
8+
for host, status in live_hosts:
9+
print(f"{host} --> {status}")
10+
else:
11+
print("\nNo devices up and running in the given range of network.")
12+
13+
14+
if __name__ == "__main__":
15+
functions.instructions()
16+
main()

0 commit comments

Comments
 (0)