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

Commit

Permalink
Network Scripts directory added (#611)
Browse files Browse the repository at this point in the history
Added pingsweep-network-scanner in Network_Scripts/.

Signed-off-by: Jayaditya Dev <[email protected]>
  • Loading branch information
jayadityadev authored Oct 10, 2023
1 parent a561a83 commit 713fc74
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
66 changes: 66 additions & 0 deletions Network_Scripts/pingsweep_network_scanner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Ping Sweep Network Scanner

## Table of Contents

- [Overview](#overview)
- [Features](#features)
- [Usage](#usage)
- [Example](#example)

## Overview

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.

## Features

- Scan a range of IP addresses within a subnet.
- Detect live hosts within the specified range.
- Cross-platform compatibility (Windows and Unix-like systems).

## Usage

1. Run the program

* For Windows (Powershell/CMD):

```
python main.py
```

* For Linux (bash/zsh/unix):

```bash
sudo python3 main.py
```

`Root privilege is required for linux users, as modern kernels of linux don't allow pinging without root privilege.`
2. Follow the on-screen instructions to provide the following information:
* Subnet IP (e.g., 192.168.0)
* Starting IP range
* Ending IP range
## Example
```
Enter the SUBNET IP: 192.168.1
Enter Starting Range: 1
Enter Ending Range: 10
```
The script will scan the hosts ranging from IP Address: 192.168.1.1 to 192.168.1.10.
```
Scanning completed in 0:00:13.741418
Live Hosts:
192.168.1.1 --> Live
192.168.1.2 --> Live
192.168.1.5 --> Live
192.168.1.7 --> Live
192.168.1.9 --> Live
```
---
`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.`
42 changes: 42 additions & 0 deletions Network_Scripts/pingsweep_network_scanner/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import platform
from datetime import datetime
import subprocess


def instructions():
print("""
1. Enter an IP range for the ping sweep.
2. Enter the range to start ping from.
3. Enter the range to end ping at.
Example: -192.168.0
-2
-8
Script will scan from 192.168.0.2 to 192.168.0.8 \n""")


def network_info():
subnet_ip = input('Enter the SUBNET IP: ')
first_host = int(input('Enter Starting Range: '))
last_host = int(input('Enter Ending Range: ')) + 1
return subnet_ip, first_host, last_host


def network_scan():
subnet_ip, first_host, last_host = network_info()
time1 = datetime.now()
live_hosts = []

for ip in range(first_host, last_host):
addr = f"{subnet_ip}.{ip}"
command = f"ping -n 1 -w 2500 {addr}" if platform.system() == 'Windows' else f"ping -c 1 -W 2 {addr}"
response = subprocess.run(command, capture_output=True, text=True, shell=True)

if "TTL" in response.stdout or "ttl" in response.stdout:
live_hosts.append((addr, 'Live'))

time2 = datetime.now()
total = time2 - time1
print("\nScanning completed in", total)

return live_hosts
16 changes: 16 additions & 0 deletions Network_Scripts/pingsweep_network_scanner/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import functions


def main():
live_hosts = functions.network_scan()
if live_hosts:
print("\nLive Hosts:")
for host, status in live_hosts:
print(f"{host} --> {status}")
else:
print("\nNo devices up and running in the given range of network.")


if __name__ == "__main__":
functions.instructions()
main()

0 comments on commit 713fc74

Please sign in to comment.