summaryrefslogtreecommitdiffstats
path: root/openbsc/tools
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2009-06-10 05:40:52 +0800
committerHarald Welte <laforge@gnumonks.org>2009-06-10 05:40:52 +0800
commit13e10daa330ea2b699c9aa9d14b3adbd01111fd6 (patch)
treebf9144f9cf625baab472492b3047970cab14ef83 /openbsc/tools
parentf7c43524cfc6e30a0223d3aaff89fe955d6e5146 (diff)
move openbsc into its own subdirectory
Diffstat (limited to 'openbsc/tools')
-rwxr-xr-xopenbsc/tools/hlrstat.pl58
1 files changed, 58 insertions, 0 deletions
diff --git a/openbsc/tools/hlrstat.pl b/openbsc/tools/hlrstat.pl
new file mode 100755
index 0000000..a3fd2b8
--- /dev/null
+++ b/openbsc/tools/hlrstat.pl
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+use strict;
+use DBI;
+my $dbh = DBI->connect("dbi:SQLite:dbname=hlr.sqlite3","","");
+
+
+my %mcc_names;
+my %mcc_mnc_names;
+
+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");
+
+$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 (keys %country_count) {
+ printf("%s: %d\n", $mcc_names{$c}, $country_count{$c});
+}
+ foreach my $k (keys %oper_count) {
+ printf("\t%s: %d\n", $mcc_mnc_names{$k}, $oper_count{$k});
+ }
+#//}