4

Summary

I am using an MT4000 telemetry device to broadcast data over port 30000, then a python udp listener to receive this data and insert it into a database. A PHP page then reads that data and displays the data, in JSON format currently.

The Goal

I would like to add a feature on the web page to allow the user to select which device they are seeing data from, as a filter.

The Method

I want to use python to programmatically extract the devices IMEI number, a way of uniquely identifying the device. I know the IMEI is located in each packet sent, and is a 15 digit number.

The Solution

What is the theory behind adding the filter to the page. If you want to down-vote (or even not), please leave a reason, so I can improve my question writing. Thanks.

Community
  • 1
  • 1
Ed Prince
  • 714
  • 2
  • 14
  • 31
  • Is your question about extracting data from a UDP stream you sniff? I'm not sure I understand – toasted_flakes Aug 21 '14 at 14:19
  • Sorry, the question was about how to locate the IMEI within the packet, preferably using python to extract. – Ed Prince Aug 21 '14 at 14:51
  • do you have any code written or have attempted to solve this at all on your own? – Jonno_FTW Aug 22 '14 at 04:23
  • Yes, but my PC crashed this morning. It should be up and running by the end of the day. The code I have is all what was mentioned in the summary of the question, what would you like to see? – Ed Prince Aug 22 '14 at 14:12

1 Answers1

2

Do you know where exactly the number is (i.e it's offset in the packet)? Or you know only that somewhere in the packet there are 15 digits in a row which are the IMEI?

If the answer to the first question is yes then there shouldn't be any problem to extract the IMEI, so I suppose this is not the case.

The following applies only if the packet structure is totally unknown, so all you can do is to search for 15 digits in a row and hope that these are the IMEI.

If the packet contents is represented as a string in your Python code (or if you can convert it to a string), again the easiest (but not the most effective) way might be to use regular expressions, like \d{15}.

Another approach is to manually traverse through packet (supposing it's a string):

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;
toasted_flakes
  • 2,502
  • 1
  • 23
  • 38
Anton Savin
  • 40,838
  • 8
  • 54
  • 90
  • Thank you for getting back, but the question was actually about how to find the IMEI number from a specific device. – Ed Prince Aug 21 '14 at 14:48
  • Do you know the packet structure? Check the updated answer. – Anton Savin Aug 21 '14 at 15:19
  • I have tried to work out where the location within the packet is using tcpdump on port 30000, but it's not receiving anything that I broadcast over that port. Thank you for the response, that is what I was looking for. If I can analyse the packet, I'll update and let you know. – Ed Prince Aug 21 '14 at 15:26
  • You are welcome! And sorry for my stupid first answer :) – Anton Savin Aug 21 '14 at 16:53