aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-07-04 23:08:44 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-07-12 23:17:10 +0000
commit29b9206e804e8e5d5f6ea6f9d8c1f8af35332480 (patch)
tree77eed5bde035b276b63f92c0f23e944049e59897 /tools
parent9e3c66b1814246f6c06a6f78975f54dfe9e2cf8c (diff)
move openbsc/* to repos root
This is the first step in creating this repository from the legacy openbsc.git. Like all other Osmocom repositories, keep the autoconf and automake files in the repository root. openbsc.git has been the sole exception, which ends now. Change-Id: I9c6f2a448d9cb1cc088cf1cf6918b69d7e69b4e7
Diffstat (limited to 'tools')
-rwxr-xr-xtools/hlrstat.pl73
1 files changed, 73 insertions, 0 deletions
diff --git a/tools/hlrstat.pl b/tools/hlrstat.pl
new file mode 100755
index 000000000..668fc9a4a
--- /dev/null
+++ b/tools/hlrstat.pl
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+
+use strict;
+use DBI;
+my $dbh = DBI->connect("dbi:SQLite:dbname=hlr.sqlite3","","");
+
+
+my %mcc_names;
+my %mcc_mnc_names;
+
+sub get_mcc_mnc_name($)
+{
+ my $mcc_mnc = shift;
+ my $ret = $mcc_mnc;
+
+ if ($mcc_mnc_names{$mcc_mnc} ne '') {
+ $ret = $mcc_mnc_names{$mcc_mnc};
+ }
+
+ return $ret;
+}
+
+sub read_networks($)
+{
+ my $filename = shift;
+ my $cur_name;
+
+ open(INFILE, $filename);
+ while (my $l = <INFILE>) {
+ chomp($l);
+ if ($l =~ /^#/) {
+ next;
+ }
+ if ($l =~ /^\t/) {
+ my ($mcc, $mnc, $brand, $r) = split(' ', $l, 4);
+ #printf("%s|%s|%s\n", $mcc, $mnc, $brand);
+ $mcc_mnc_names{"$mcc-$mnc"} = $brand;
+ $mcc_names{$mcc} = $cur_name;
+ } elsif ($l =~ /^(\w\w)\t(.*)/) {
+ #printf("%s|%s\n", $1, $2);
+ $cur_name = $2;
+ }
+ }
+ close(INFILE);
+}
+
+read_networks("networks.tab");
+
+my %oper_count;
+my %country_count;
+
+#my $sth = $dbh->prepare("SELECT imsi FROM subscriber where authorized=1");
+my $sth = $dbh->prepare("SELECT imsi FROM subscriber");
+
+$sth->execute();
+
+while (my $href = $sth->fetchrow_hashref) {
+ my ($mcc, $mnc) = $$href{imsi} =~ /(\d{3})(\d{2}).*/;
+ #printf("%s %s-%s \n", $$href{imsi}, $mcc, $mnc);
+ $oper_count{"$mcc-$mnc"}++;
+ $country_count{$mcc}++;
+}
+
+
+foreach my $c (sort{$country_count{$b} <=> $country_count{$a}} keys %country_count) {
+ printf("%s: %d\n", $mcc_names{$c}, $country_count{$c});
+
+ foreach my $k (sort{$oper_count{$b} <=> $oper_count{$a}} keys %oper_count) {
+ if ($k =~ /^$c-/) {
+ printf("\t%s: %d\n", get_mcc_mnc_name($k), $oper_count{$k});
+ }
+ }
+}