Skip to content

Commit d97902b

Browse files
committed
add finding past wifi connections on windows tutorial
1 parent cb538e4 commit d97902b

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
6161
- [How to Create A Fork Bomb in Python](https://thepythoncode.com/article/make-a-fork-bomb-in-python). ([code](ethical-hacking/fork-bomb))
6262
- [How to Implement 2FA in Python](https://thepythoncode.com/article/implement-2fa-in-python). ([code](ethical-hacking/implement-2fa))
6363
- [How to Build a Username Search Tool in Python](https://thepythoncode.com/code/social-media-username-finder-in-python). ([code](ethical-hacking/username-finder))
64+
- [How to Find Past Wi-Fi Connections on Windows in Python](https://thepythoncode.com/article/find-past-wifi-connections-on-windows-in-python). ([code](ethical-hacking/find-past-wifi-connections-on-windows))
6465

6566
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
6667
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Find Past Wi-Fi Connections on Windows in Python](https://thepythoncode.com/article/find-past-wifi-connections-on-windows-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import winreg # Import registry module.
2+
3+
def val2addr(val): # Convert value to address format.
4+
addr = '' # Initialize address.
5+
try:
6+
for ch in val: # Loop through value characters.
7+
addr += '%02x ' % ch # Convert each character to hexadecimal.
8+
addr = addr.strip(' ').replace(' ', ':')[0:17] # Format address.
9+
except:
10+
return "N/A" # Return N/A if error occurs.
11+
return addr # Return formatted address.
12+
13+
14+
def printNets(): # Print network information.
15+
net = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged" # Registry key for network info.
16+
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, net) # Open registry key.
17+
print('\n[*] Networks You have Joined:') # Print header.
18+
for i in range(100): # Loop through possible network keys.
19+
try:
20+
guid = winreg.EnumKey(key, i) # Get network key.
21+
netKey = winreg.OpenKey(key, guid) # Open network key.
22+
try:
23+
n, addr, t = winreg.EnumValue(netKey, 5) # Get MAC address.
24+
n, name, t = winreg.EnumValue(netKey, 4) # Get network name.
25+
if addr:
26+
macAddr = val2addr(addr) # Convert MAC address.
27+
else:
28+
macAddr = 'N/A'
29+
netName = str(name) # Convert network name to string.
30+
print(f'[+] {netName} ----> {macAddr}') # Print network info.
31+
except WindowsError: # Handle errors.
32+
pass # Continue loop.
33+
winreg.CloseKey(netKey) # Close network key.
34+
except WindowsError: # Handle errors.
35+
break # Exit loop.
36+
winreg.CloseKey(key) # Close registry key.
37+
38+
39+
printNets() # Call printNets function.

0 commit comments

Comments
 (0)