Change in docker-playground[master]: osmo-ci-latest: Add options to change mcc/mnc for SIM card data

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Mar 29 11:14:16 UTC 2019


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/13440 )

Change subject: osmo-ci-latest: Add options to change mcc/mnc for SIM card data
......................................................................

osmo-ci-latest: Add options to change mcc/mnc for SIM card data

Change-Id: Ica348dc12f07a1a57729c4d97a40cf9c04e975c9
---
M osmo-cn-latest/create_hlr.py
1 file changed, 24 insertions(+), 6 deletions(-)

Approvals:
  Daniel Willmann: Verified
  Harald Welte: Looks good to me, approved



diff --git a/osmo-cn-latest/create_hlr.py b/osmo-cn-latest/create_hlr.py
index 4285ea6..b754af7 100755
--- a/osmo-cn-latest/create_hlr.py
+++ b/osmo-cn-latest/create_hlr.py
@@ -3,8 +3,17 @@
 import csv
 import sys
 import sqlite3
+from optparse import OptionParser
 
-# 3G
+def parse_options():
+    parser = OptionParser()
+
+    parser.add_option("-c", "--mcc", dest="mcc", help="Mobile Country Code")
+    parser.add_option("-n", "--mnc", dest="mnc", help="Mobile Network Code")
+    (options, args) = parser.parse_args()
+
+    return options, args
+
 def create_hlr_3g(db):
 	conn = sqlite3.connect(db)
 	c = conn.execute(
@@ -112,7 +121,10 @@
 	conn.commit()
 	conn.close()
 
-def main(infilename):
+def main():
+        options, args = parse_options()
+
+        infilename = args[0]
 	csvfields = ['name', 'iccid', 'mcc', 'mnc', 'imsi', 'extension', 'smsp', 'ki', 'opc', 'adm1']
 
 	create_hlr_3g("hlr.db")
@@ -124,12 +136,18 @@
 
 	cw.writeheader()
 	for row in cr:
+		imsi = row['imsi']
+                if options.mcc:
+                    imsi = options.mcc + imsi[3:]
+                if options.mnc:
+                    imsi = imsi[0:3] + options.mnc + imsi[5:]
+                    
 		data = {}
 		data['name'] = "Subscriber " + row['iccid'][-6:-1]
 		data['iccid'] = row['iccid']
-		data['mcc'] = row['imsi'][0:3]
-		data['mnc'] = row['imsi'][3:5]
-		data['imsi'] = row['imsi']
+                data['imsi'] = imsi
+		data['mcc'] = data['imsi'][0:3]
+		data['mnc'] = data['imsi'][3:5]
 		data['ki'] = row['ki']
 		data['opc'] = row['opc']
 		data['extension'] = row['iccid'][-6:-1]
@@ -143,5 +161,5 @@
 
 
 if __name__ == '__main__':
-    main(sys.argv[1])
+    main()
 

-- 
To view, visit https://gerrit.osmocom.org/13440
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: docker-playground
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ica348dc12f07a1a57729c4d97a40cf9c04e975c9
Gerrit-Change-Number: 13440
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Willmann <dwillmann at sysmocom.de>
Gerrit-Reviewer: Daniel Willmann <dwillmann at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190329/6b8c13a9/attachment.html>


More information about the gerrit-log mailing list