程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

In order to fish at work, I use Python to monitor my boss!

編輯:Python

As a worker , especially 996,、007 The job of , Besides cooking , The most intense and exciting thing is to sneak away occasionally at work , Go and fish in the pond .

What fish do ordinary people touch ? Chat 、 Microblogging 、 WeChat friend circle 、 Little games 、 A novel 、 Stock funds, etc .

What is the biggest obstacle to fishing ? Of course, the contractor ( Boss ) 了 , They want workers 24 Work hour after hour .

But human energy is limited , You can only concentrate on a few hours a day , Other times need to be adjusted by fishing , So as long as we fish without being found by the contractor , That's quite a pleasant thing .

So , I use Python I wrote a little tool ——BOSS coming , To monitor the boss , Reduce the probability of catching fish .

Ideas

We know , Each computer or mobile phone terminal has a fixed Mac Address , And our company has several office areas AP , Everyone's mobile phone is connected to the nearest one AP , So in theory, if I know the owner's mobile phone Mac Address , Then scan the LAN for all Mac Address , If the boss's mobile phone appears Mac Address , So the boss is probably near me , Fishing is dangerous at this time ; If there is no boss Mac Address , Then the boss may be far away from me , It's safer to fish at this time .

Based on the above ideas , All I have to do is get the boss's mobile phone Mac Address , All LANs are polled continuously Mac Address , Once the boss's mobile phone appears Mac Address , I'll work honestly , Once the boss Mac The address disappeared , You can fish .

Realization

Get the boss's mobile phone Mac Address

How to get the boss's mobile phone Mac Address ?

Many people may feel hopeless when they hear this ! You can't steal the boss's mobile phone , Then go to the settings to find it .

Heaven never shuts one door but opens another , As long as you use your head , There are many ways !

My approach is this . When other colleagues don't move , When the boss comes , Save the LAN once Mac Address information , Save it again when the boss leaves , And then compare them , Find out the owner's mobile phone Mac Address . To ensure accuracy , Try it a few more times .

Get all Mac Address

First step , Use ipconfig/all command , You can find the current network segment :

The second step , Use the polling command one by one ping In a segment IP , This step is to establish ARP surface . The order is as follows :

for /L %i IN (1,1,254) DO ping -w 1 -n 1 192.168.1.%i

among ,192.168.1.%i Is the network segment to query .

The third step , Use arp Command can query all Mac Address , The order is :

arp -a

After running , You will see results similar to the following :

<figcaption >mac Address list </figcaption>

Code implementation

The idea has been verified , The preparations have been made , Next is the code implementation .

First , We follow the above ideas , First write a to get all the information on the LAN Mac Address method .

def get_macs():
# function cmd Control window , Input “arp -a”, And deliver the content to res in
res = os.popen("arp -a")
# Read res data , Convert to readable data
arps = res.read()
print(arps)
# What will be obtained counts The data in is based on “ A newline ” To split and slice
result = arps.split('\n')
# Set an empty list to load ip
ips = []
# Set an empty list to load mac
macs = []
# Traverse
for i in range(1, len(result)):
# Get... In the list idx Data
line = result[i]
if ('Internet' in line) | ('' == line) | (' Interface ' in line):
continue
# according to “ ” Slice
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

then , Write a timed poll .

# 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
# If boss coming , Every other day 5 Scan every minute
sleep_time = 300
# Prompt alarm
choice = g.msgbox(msg=" There's an inner ghost , Terminate the transaction !", title="OMG")
break
if is_come == 0:
# If boss go , Every other day 5 Scan every second
sleep_time = 5
g.msgbox(msg=" Everything is all right !", title="OMG")

What I'm setting here is : If the boss shows up , Every other day 5 Poll every minute , Because if the boss is here , Concentrate on your work , Don't think about fishing too often . If the boss leaves , Every other day 5 Poll every second , It's better to give frequent early warning when fishing !

Run the program , When the boss comes , The warning pop-up window is like this :

When the boss disappears , The content of the pop-up window is like this :

summary

Of course , If the boss doesn't drive WiFi , Then this method fails . Or the boss comes , however The response of the mobile phone is slow , Didn't switch to this side AP , There will also be danger . So don't rely entirely on this gadget , When fishing, you should occasionally observe the surrounding environment .

Source code :https://github.com/JustDoPython/python-examples/tree/master/xianhuan/bosscoming

At the end of the article

Your favorite collection is my greatest encouragement ! Welcome to follow me , Share Python dried food , communication Python technology . What's your opinion on the article , Or any technical problems , Welcome to leave a message and discuss in the comment area !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved