Python: use a filter to find an IMEI device?

Summary

I use the MT4000 telemetry device to transmit data through port 30000, and then the pudon udp listener to receive this data and insert it into the database. The PHP page then reads this data and displays the data in JSON format at this time.

purpose

I would like to add a function on the web page so that the user can choose on which device they see the data as a filter.

Method

I want to use python to programmatically extract IMEI device numbers, a way to uniquely identify a device. I know that IMEI is in every packet sent and is a 15-digit number.

Decision

What is the theory of adding a filter to a page. If you want to vote (or even not), please leave a reason, so I can improve my letter. Thank.

+4
source share
1 answer

Do you know where exactly this number is (that is, it is shifted in the packet)? Or do you only know that somewhere in the package there are 15 digits in a string that are IMEI?

If the answer to the first question is yes, then there should not be any problems with extracting the IMEI, so I believe that it is not.

The following applies only if the package structure is completely unknown, so all you can do is search for 15 digits per line and hope this is IMEI.

Python ( ), ( ) , \d{15},

, (, ):

def findImei(packet):
    start = -1;
    cnt = 0;
    for i, c in enumerate(packet):
        if not c.isdigit():
            cnt = 0;
            continue;
        if cnt == 0:
            start = i;
        cnt += 1;
       if cnt == 15:
           return packet[start : i + 1]
    return None;
+2

All Articles