It's a good thing to use Python as a fishing artifact to monitor the boss

Posted by stebut05 on Fri, 21 Jan 2022 11:53:15 +0100

This article is reproduced from Crossin's programming classroom

As a migrant worker, especially in 996 and 007, in addition to dry meals, the most exciting thing is to sneak around occasionally at work and touch fish pictures in the pond

Which fish do ordinary people touch? Chat, microblog, wechat circle of friends, games, novels, stock funds, etc.

What is the biggest obstacle to fishing? Of course, it's the contractor (boss). They want workers to work 24 hours a day.

However, people's energy is limited. They can only concentrate on working for a few hours a day. Other times need to be adjusted by fishing. Therefore, it is quite pleasant as long as we don't get caught by the contractor.

To this end, I wrote a small tool - "BOSS" in Python to monitor the BOSS and reduce the probability of fishing being found
thinking

We know that each computer or mobile phone and other terminals have a fixed Mac address, and there are several APS in our company's office area. Everyone's mobile phones are connected to the AP closest to them, so theoretically, if I know the Mac address of the boss's mobile phone, and then scan all Mac addresses on the LAN, if the Mac address of the boss's mobile phone appears, The boss is probably near me. It's dangerous to fish at this time; If there is no Mac address of the boss, 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 Mac address of the boss's mobile phone, and then constantly poll all Mac addresses on the LAN. Once I find the Mac address of the boss's mobile phone, I will work honestly. Once the boss's Mac address disappears, I can fish.

realization

Get the boss's mobile Mac address

How do you get the boss's mobile Mac address?

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

There's no way out of heaven. As long as you're willing to use your brain, there are many ways!

My method is like this. When other colleagues don't walk around, when the boss comes, save the Mac address information of the LAN once. When the boss leaves, save it again, and then compare it to find out the Mac address of the boss's mobile phone. In order to ensure accuracy, you can try several times.

Get all Mac addresses

Step 1: use the ipconfig/all command to find the current network segment:

IP segment

The second step is to use the polling command to ping the IP addresses in the network segments one by one. This step is to establish the ARP table. The command is as follows:

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

Of which, 192.168.1% I is the network segment to query.

Step 3: use the arp command to query all Mac addresses. The command is:

arp -a

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

mac address list

code implementation

The idea has been verified and the preparations have been made. The next step is the code implementation.

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

def get_macs():
    # Run the cmd control window, enter "arp -a", and pass the content to res
    res = os.popen("arp -a")
    # Read res data and convert it into readable data
    arps = res.read()
    print(arps)
 
    # Divide and slice the data in the obtained counts according to the "newline character"
    result = arps.split('\n')
 
    # Set an empty list to load ip
    ips = []
    # Set an empty list to install mac
    macs = []
 
    # ergodic
    for i in range(1, len(result)):
        # Get the idx data in the list
        line = result[i]
        if ('Internet' in line) | ('' == line) | ('Interface' in line):
            continue
        # Slice according to ''
        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 the boss comes, scan every five minutes
            sleep_time = 300
            # Prompt alarm
            choice = g.msgbox(msg="There's an insider, stop the deal!", title="OMG")
            break
    if is_come == 0:
        # If the boss is gone, scan every five seconds
        sleep_time = 5
        g.msgbox(msg="business as usual!", title="OMG")

What I set here is: if the boss appears, poll every 5 minutes, because if the boss is there, you should concentrate on your work and don't think about fishing too often. If the boss is gone, poll every 5 seconds. It's better to give frequent early warning when fishing!

Run the program. When the boss comes, the warning pop-up window looks like this:

There's an insider

When the boss disappears, the content of the pop-up window is as follows:

The boss is gone
summary

Of course, if the boss doesn't turn on WiFi, this method will fail. Or the boss comes, but the mobile phone response is slow and does not switch to the AP here, it will also be dangerous. So don't rely entirely on this gadget. When fishing, you should occasionally observe the surrounding environment.

Finally, I still have to remind you: small touch is pleasant, big touch hurts your body!

Industry API interface: https://www.wapi.cn(https://www.wapi.cn/?from=promoter@637)

Topics: Python Java Mac stack LAN