diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2019-09-12 13:03:23 +0200 |
---|---|---|
committer | Philipp Maier <pmaier@sysmocom.de> | 2019-09-13 11:04:13 +0200 |
commit | 7592eeea5943cff129514beb376d8269a999aa5e (patch) | |
tree | 8d2e652e0e9b7397101c7250cd3c3d09ae97c597 /pySim/utils.py | |
parent | be069e26ae6e6d0e6aaa50498f274bddebe8e99e (diff) |
pySim-prog: use functions to derive MCC/MNC from IMSI
In case the MCC/MNC are not supplied with a CSV file we cut out the
missing values from the IMSI string. Lets use a function to do this and
also check the input parameters.
Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8
Diffstat (limited to 'pySim/utils.py')
-rw-r--r-- | pySim/utils.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py index a68af0a..e8dd531 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -206,3 +206,30 @@ def calculate_luhn(cc): num = map(int, str(cc)) check_digit = 10 - sum(num[-2::-2] + [sum(divmod(d * 2, 10)) for d in num[::-2]]) % 10 return 0 if check_digit == 10 else check_digit + +def mcc_from_imsi(imsi): + """ + Derive the MCC (Mobile Country Code) from the first three digits of an IMSI + """ + if imsi == None: + return None + + if len(imsi) > 3: + return imsi[:3] + else: + return None + +def mnc_from_imsi(imsi, long=False): + """ + Derive the MNC (Mobile Country Code) from the 4th to 6th digit of an IMSI + """ + if imsi == None: + return None + + if len(imsi) > 3: + if long: + return imsi[3:6] + else: + return imsi[3:5] + else: + return None |