Python Tool for Detecting Boss Presence via LAN MAC‑Address Scanning
This article describes a Python script that monitors the local network for the boss's phone MAC address, using ARP scans to infer his proximity and automatically alerts the user to stop or resume non‑work activities, complete with step‑by‑step implementation and code examples.
Idea
Each device on a network has a fixed MAC address; by scanning the LAN for the boss's phone MAC address we can infer his proximity. When the MAC appears, the boss is nearby and the user should stop "slacking"; when it disappears, it is safe to resume non‑work activities.
Implementation
Get boss phone MAC address
The boss's MAC is obtained by capturing the ARP table before the boss arrives, then again after he leaves, and comparing the two lists. Repeating the process several times improves accuracy.
Get all MAC addresses
Step 1: Use the ipconfig /all command to determine the current network segment.
Step 2: Ping every IP in the segment to populate the ARP table, e.g.:
for /L %i IN (1,1,254) DO ping -w 1 -n 1 192.168.1.%i
Step 3: Run arp -a to list all MAC addresses on the network.
Code implementation
The following Python functions implement the above steps.
<code>def get_macs():
# Run cmd and execute "arp -a", capture output
res = os.popen("arp -a")
arps = res.read()
print(arps)
# Split output by newline
result = arps.split('\n')
ips = []
macs = []
for i in range(1, len(result)):
line = result[i]
if ('Internet' in line) | ('' == line) | ('接口' in line):
continue
line_split = line.split(" ")
index = 0
for l in line_split:
if l != '':
index += 1
if index == 1:
ips.append(l)
elif index == 2:
macs.append(l)
return ips, macs
</code>Then a polling loop checks for the boss's MAC address:
<code># Boss's MAC address
bossMac = "01-00-5e-0b-14-01"
sleep_time = 5
while 1 == 1:
time.sleep(sleep_time)
ips, macs = get_macs()
is_come = 0
for mac in macs:
if mac == bossMac:
is_come = 2
# Boss is present – scan every 5 minutes
sleep_time = 300
choice = g.msgbox(msg="有内鬼,终止交易!", title="OMG")
break
if is_come == 0:
# Boss left – scan every 5 seconds
sleep_time = 5
g.msgbox(msg="一切正常!", title="OMG")
</code>The script shows a warning dialog when the boss is detected and a normal‑status dialog when he leaves.
Summary
The method relies on the boss's phone being connected to the same Wi‑Fi; if Wi‑Fi is off or the phone does not switch to the local AP, the tool will not work, so users should still stay aware of their surroundings.
Finally, remember that occasional "slacking" can be refreshing, but excessive "slacking" can be harmful.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.