Skip to content

Commit

Permalink
1.0 Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
babylard committed Jul 7, 2024
1 parent 9115c05 commit e9924f4
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Documentation/docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
"metadata": {},
"source": [
"# Setup\n",
"First of all, you will need to install Packet capturing software for the program to function properly. Here are some good options:\n",
"First of all, you will need to install Packet capturing software for the program to function properly. Here are some good options you can choose from:\n",
"1. [NpCap](https://npcap.com/#download)\n",
"2. [WinPcap](https://www.winpcap.org/install/default.htm)\n",
"3. [Nmap](https://nmap.org/download.html)\n",
"\n",
"If wouldn't use WinPcap, as it has ceased development quite a long time ago and is vunreble to DLL Injections and such, however if you're not worried about security then it should work just fine. For more information on vunrebilities of using WinPcap you can visit their [website](https://www.winpcap.org/). For Mac users, I reccomend using Nmap.\n",
"I wouldn't use WinPcap, as it has ceased development a long time ago, but if you're not worried about security then it should work just fine. For more information you can visit their [website](https://www.winpcap.org/).\n",
"\n",
"Please note that you are only required to have one of these, or other software with the same functionality.\n",
"\n",
"If you are using a `.py` file rather than a `.exe` from releases (`.py` files will be used as of 0.0.4), you will need to first correctly install Python from [Python.org](https://www.python.org). Afterwards, open a Terminal, and make sure it is located in the downloaded NetScan folder, and run `pip install -r requirements.txt` to install all required dependencies.\n",
"\n",
"# Basic Usage\n",
"\n",
"To begin, Input the IP Address of your Router/AP, along with the range. If you dont know what an IP range is, you can just leave it as is and it will function just fine. Both fields will be set properly as of 0.0.3, so they can be left as is unless you would like to make changes. The TUI version currently does not have this functionality. There is also a checkbox labeled \"Show short OUIs\" which when checked, will show an 8 character long version of listed manufacturers to preserve space since these can often be quite long, espesially from foriegn manufacturers. When left unchecked, the full length will be outputted. The TUI version now has this ability as of 0.8\n",
"To begin, Input the IP Address of your Router/AP, along with the range. If you dont know what an IP range is, you can just leave it as is and it will function just fine. Both fields will be set properly by default, so they can be left as is unless you would like to make changes. There is also a checkbox labeled \"Show short OUIs\" which when checked, will show an 8 character long version of listed manufacturers to reserve space since these can often be quite long, espesially from foriegn manufacturers. When left unchecked, the full length will be outputted. The TUI version now has this ability as of 0.8\n",
"\n",
"Once everything is set to your preference, press `Scan Network`. The program will list devices it finds in realtime, and when finished you should have list of every devices IP, MAC Address, OS, etc.\n",
"\n",
Expand Down
116 changes: 106 additions & 10 deletions GUI/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Imports
import customtkinter as ctk
from tkinter import messagebox
from tkinter import *
from tkinter import filedialog
from scapy.all import *
import scapy.all as scapy
from scapy.layers.dot11 import RadioTap, Dot11, Dot11Deauth
Expand All @@ -10,6 +10,8 @@
import threading
import sys
import webbrowser
import json
import os

# Variables
hostname = conf.route.route("0.0.0.0")[2]
Expand Down Expand Up @@ -43,10 +45,19 @@ def deauth_function(target_mac, bssid, count=1):
scapy.send(deauth_packet, verbose=False)

time.sleep(10)
print("Deauthed for 10 Seconds, repeating...")
except:
print("Invalid input.")

def portscan_function(ip):
for port in range(65535):
try:
serv = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
serv.bind((ip,port))
except:
print('\033[1;32;40m [OPEN]: ', port)

serv.close() #close connection

def start_deauth(target_mac, bssid, count=1):
global deauth_thread

Expand All @@ -62,6 +73,15 @@ def stop_deauth_thread():
stop_deauth_event.set()
print("Stopped Deauth.")

def start_portscan(ip):
global portscan_thread

if portscan_thread and portscan_thread.is_alive():
stop_portscan_thread()

portscan_thread = threading.Thread(target=portscan_function, args=(ip))
portscan_thread.start()

def get_device_type(mac_address):
global show_short_oui
p = manuf.MacParser()
Expand Down Expand Up @@ -129,7 +149,6 @@ def scan_thread(ip):
scanning_thread.start()

# GUI

ctk.set_appearance_mode("system")
ctk.set_default_color_theme("green")

Expand All @@ -142,7 +161,7 @@ def on_deauth():
router_mac = router_entry.get()
if target_mac and router_mac:
start_deauth(target_mac=target_mac, bssid=router_mac)
deauth_output.insert(ctk.END, f"Deauthing {target_mac}, this lasts about 10 seconds and will be looped every 10 seconds.\n--------------------------------------------------------------------\n")
deauth_output.insert(ctk.END, f"Deauth loop started.\n--------------------------------------------------------------------\n")
else:
deauth_output.insert(ctk.END, "Values not set. Please enter details in both Target MAC and Router MAC. If you need any help, feel free to read the documentation.\n")

Expand Down Expand Up @@ -171,10 +190,10 @@ def validate_numeric_input(value):
return all(char.isdigit() or char == "." for char in value) or value == ""

def main_window():
global root, output_text
global root, output_text, ip_entry, range_entry
root = ctk.CTk()
root.title("NetScan")
root.geometry("753x600")
root.geometry("753x558")

validate_command = root.register(validate_numeric_input)

Expand All @@ -186,6 +205,58 @@ def on_scan_network():

def on_clear_output():
output_text.delete(1.0, ctk.END)

def donothing():
print("Unimplemented")

def save():
# Open a file dialog to choose the save location
file_path = filedialog.asksaveasfilename(defaultextension=".json", filetypes=[("JSON files", "*.json"), ("All files", "*.*")])
if file_path:
# Sanitize file name by removing invalid characters
file_name = os.path.basename(file_path)
sanitized_file_name = "".join(c for c in file_name if c.isalnum() or c in "_-.")

# Add "NetScan_" to the beginning of the file name
if not sanitized_file_name.endswith(".json"):
sanitized_file_name += ".json"
if not sanitized_file_name.startswith("NetScan_"):
sanitized_file_name = "NetScan_" + sanitized_file_name

# Construct full file path with sanitized file name
save_file_path = os.path.join(os.path.dirname(file_path), sanitized_file_name)

# Save the current state to a JSON file
data = {
"router_ip": ip_entry.get(),
"ip_range": range_entry.get(),
"output": output_text.get(1.0, ctk.END),
"short_oui": oui_var.get()
}
with open(save_file_path, 'w') as file:
json.dump(data, file, indent=4)
print(f"File saved to {save_file_path}")

def open_file():
# Open a file dialog to choose the file to open
file_path = filedialog.askopenfilename(filetypes=[("JSON files", "*.json"), ("All files", "*.*")])
if file_path:
# Check if the file is valid for your program
if not file_path.endswith(".json") or not os.path.basename(file_path).startswith("NetScan_"):
print(f"Invalid file selected: {file_path}")
return

# Load the state from the JSON file
with open(file_path, 'r') as file:
data = json.load(file)
ip_entry.delete(0, ctk.END)
ip_entry.insert(0, data["router_ip"])
range_entry.delete(0, ctk.END)
range_entry.insert(0, data["ip_range"])
output_text.delete(1.0, ctk.END)
output_text.insert(ctk.END, data["output"])
oui_var.set(data.get("short_oui", False))
print(f"File loaded from {file_path}")

ctk.CTkLabel(root, text="Router IP").grid(row=0, column=0, padx=1, pady=1, sticky="w")
ctk.CTkLabel(root, text="IP Range").grid(row=0, column=1, padx=1, pady=1, sticky="w")
Expand All @@ -210,10 +281,35 @@ def on_clear_output():
sys.stdout = TextRedirector(output_text)

ctk.CTkButton(root, text="Scan Network", command=on_scan_network).grid(row=3, column=0, padx=5, pady=5, sticky="w")
ctk.CTkButton(root, text="Deauth a device", command=deauth_window).grid(row=3, column=1, padx=5, pady=5, sticky="w")
ctk.CTkButton(root, text="Help", command=docs).grid(row=3, column=2, padx=5, pady=5, sticky="w")
ctk.CTkButton(root, text="Clear Output", command=on_clear_output).grid(row=4, column=0, columnspan=3, padx=5, pady=5, sticky="w")

def newfile():
on_clear_output()
range_entry.delete(0, ctk.END)
range_entry.insert(0, "24")
ip_entry.delete(0, ctk.END)
ip_entry.insert(0, hostname)
oui_var.set(False)

menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New", command=newfile)
filemenu.add_command(label="Open", command=open_file)
filemenu.add_command(label="Save", command=save)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)

helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Documentation", command=docs)
menubar.add_cascade(label="Help", menu=helpmenu)

viewmenu = Menu(menubar, tearoff=0)
viewmenu.add_command(label="Clear", command=on_clear_output)
viewmenu.add_command(label="Deauth", command=deauth_window)
viewmenu.add_command(label="Port scan", command=donothing)
menubar.add_cascade(label="View", menu=viewmenu)

root.config(menu=menubar)
root.mainloop()

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion GUI/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
manuf==1.1.5
PySimpleGUI==4.60.5
scapy==2.5.0
customtkinter==5.2.2
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# NetScan
A lightweight Network scanner which lists IPs, MAC Addresses of devices on a specified network, which is also capable of deauthing devices.
A Network scanner which lists IPs, MAC Addresses, and other information about devices on a network, which can also Deuath devices.

![image](https://github.com/babylard/NetScan/assets/75695872/5ec60a6f-acdf-4ef7-a6ea-ec1ee3adf62e)
![image](https://github.com/babylard/NetScan/assets/75695872/40ad710c-4471-4910-91e3-2e29567890dc)

# Dependencies
You may require WinPcap, Npcap, or other Packet Capturing software for the program to work properly. I highly reccomend Npcap over WinPcap, as WinPcap has ceased development a very long time ago. But if you dont care for security, WinPcap will work just fine.
You may require WinPcap, Npcap, or other Packet Capturing software for the program to work properly. These will be listed below.

Be sure to run `pip install -r requirements.txt` to install all needed modules to function.

Expand All @@ -21,6 +21,4 @@ To begin, input the IP of the router you would like to scan for connected device
Both fields will be properly set by default as of 0.0.3, then press "Scan".
The output will begin listing devices it finds in realtime, and should let you know when it is done. Afterwards you should have a neat looking list of IP's, MAC Addresses, OS information, etc.



Please view the [Documentation](https://github.com/babylard/NetScan/blob/main/Documentation/docs.ipynb) for more in depth information.
Please view the [Documentation](https://github.com/babylard/NetScan/blob/main/Documentation/docs.ipynb) for more in depth information.

0 comments on commit e9924f4

Please sign in to comment.