Article | carefree huan \

Source: Python Technology “ID: pythonall”

As a worker, especially 996, 007’s work, in addition to cooking, the most exciting than the work of occasionally secretly idle, go to the pond fish.

It is 996 fishing

What kind of fish does the average person catch? Chat, microblog, wechat circle of friends, small games, novels, stock funds and so on.

What’s the biggest obstacle to fishing? The contractors (bosses), of course, expect them to work 24 hours a day.

The boss catches fish

But people’s energy is limited, can only concentrate on so many hours a day, other time through fishing to adjust the limited, so as long as we fishing not found by the contractor, it is quite a pleasant thing.

To this end, I wrote a small tool in Python — BOSS is coming — to monitor the BOSS and reduce the probability of being caught.

Train of thought

As we know, every computer, mobile phone and other terminals has a fixed Mac address, and there are several APS in the office area of our company. Everyone’s mobile phone is connected to the NEAREST AP. Therefore, if I know the Mac address of my boss’s mobile phone and scan all THE Mac addresses in the LAN, If the Mac address of the boss’s mobile phone appears, then the boss is probably near me, and it is dangerous to touch the fish. If there is no Mac address of the boss, then the boss may be far away from me, this time it is safer to touch the fish.

All I have to do is get the Mac address of my boss’s phone, and then poll all the Mac addresses in the LAN. Once I find the Mac address of my boss’s phone, I do my job. Once the Mac address of my boss disappears, I can do my job.

implementation

Get the boss’s Mac address

How do I get the boss’s Mac address?

A lot of people hear this may feel lost! You can’t just steal the boss’s phone and look it up in Settings.

There is always a way out, as long as you are willing to use your brain, there are many ways!

Here’s how I did it. Save your LAN Mac address once when your boss is in town and again when he is gone, and then compare it to find the Mac address on his phone. To ensure accuracy, try several times.

Tact as I

Obtain all Mac addresses

The first step is to find the current network segment using the ipconfig/all command:

Network segment

The second step is to ping IP addresses in network segments one by one using polling commands to establish ARP tables. The command is as follows:

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

% I indicates the network segment to be queried.

Step 3 Run the arp command to query all Mac addresses.

arp -a

When run, you should see something like the following:

MAC Address List

Code implementation

With the idea validated and the preparation done, it’s time to implement the code.

First, we write a method to obtain all the Mac addresses of the LAN according to the above ideas.

Def get_macs(): def get_macs(): def get_macs(): def get_macs(): def get_macs(): def get_macs():"arp -a"Arps = res.read()printResult = arps.split(arps)'\n') # set an empty list of ips = [] # set an empty list of MACs = [] # traversalfor i in range(1.len(result) : line = result[I]if ('Internet' in line) | (' ' == line) | ('interface' in line):
            continueLine_split = line.split("")
        index = 0
        for l in line_split:
            ifl ! =' ':
                index += 1
                if index == 1:
                    ips.append(l)
                elif index == 2:
                    macs.append(l)

    return ips, macs
Copy the code

Then, write a timed poll.

# 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 the boss comes, cut him off5Scan every minute sleep_time =300# prompt alarm choice = g.msgbox(MSG ="There's a mole. Cut off the deal!", title="OMG")
            break
    if is_come == 0If the boss is gone, cut him off5Scan every second sleep_time =5
        g.msgbox(msg="Everything is fine!, title="OMG")
Copy the code

My goal here is to poll every 5 minutes if the boss shows up, because when he’s around, you need to focus on your work and not think about it too often. If your boss is gone, poll every 5 seconds, and give frequent warning!

When the boss arrives, the warning popup looks like this:

With the ghost

When the boss disappears, the popover looks like this:

The boss is gone

conclusion

Of course, this doesn’t work if the boss doesn’t have WiFi on. Or the boss is coming and the phone is slow and doesn’t switch to the AP over here, that’s also a danger. So don’t rely entirely on this gadget. Still, take a look at your surroundings once in a while.

Finally, we have to remind you: small touch happy, big touch hurt body!

It is said that fishing partners will go to orderpraiseandLooking at the\

PS: Reply “Python” within the public number to enter the Python novice learning exchange group, together with the 100-day plan!

Old rules, brothers still remember, the lower right corner of the “watching” click, if you feel the content of the article is good, remember to share moments to let more people know!

[Code access ****]

Identify the qr code at the end of the text, reply: 210628