3 ms·
Semi-related project I worked on: https://github.com/evidlo/nanpa_lookup https://github.com/evidlo/nanpa_lookup Simple bash script to lookup what companies own
by Evidlo 4y ago
Semi-related project I worked on: https://github.com/evidlo/nanpa_lookup https://github.com/evidlo/nanpa_lookup
Simple bash script to lookup what companies own spam numbers. Almost all of my spam calls are from domestic VOIP companies.
>>> ./lookup.sh -n 907-200-1234
"GCI COMMUNICATION CORP. DBA GENERAL COMMUNICATION"
>>> ./lookup.sh -f path/to/numbers.txt
"GCI COMMUNICATION CORP. DBA GENERAL COMMUNICATION"
"CELLCO PARTNERSHIP DBA VERIZON WIRELESS - NC"
"ONVOY, LLC - TN"
- tzs 4y agoThat example doesn't work for me. It produces no output for that number. The problem seems to be that the entry in database.csv for that number is this: 907|200||GCI COMMUNICATION CORP. DBA GE|PCS||6872 Given 907-200-1234 lookup.sh looks it up by grepping for '907\|200\|1'. Compare to a number that works, 858-598-7654. That ends up grepping for '858\|598\|7' and that matches this line from database.csv: 858|598|7|T-MOBILE USA, INC.|PCS|tmomail.net|6529 In general lookup.sh looks for the first 3 digits of the phone number in the first field of database.csv, the second 3 digits in the second field, and the next digit in the third field. Looking up 907200 or 907-200 (but not 907-200-) will match. I'd guess that the database allows a blank third field to mean that the entry covers all numbers that match the first 6 digits that aren't covered by a more explicit entry. If that's the case the database is not using that mechanism optimally. For example there is this: 360|654||ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 360|654|0|ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 360|654|1|ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 360|654|2|ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 360|654|3|ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 360|654|4|LEVEL 3 COMMUNICATIONS, LLC - |CLEC||6121 360|654|5|AT&T - LOCAL|CLEC||7421 360|654|6|LEVEL 3 COMMUNICATIONS, LLC - |CLEC||6121 360|654|7|ONVOY, LLC - WA|CLEC||483E 360|654|8|ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 360|654|9|ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 which could be reduced to: 360|654||ZIPLY FIBER NORTHWEST, LLC DBA|ICO||4324 360|654|4|LEVEL 3 COMMUNICATIONS, LLC - |CLEC||6121 360|654|5|AT&T - LOCAL|CLEC||7421 360|654|6|LEVEL 3 COMMUNICATIONS, LLC - |CLEC||6121 360|654|7|ONVOY, LLC - WA|CLEC||483E There are 92492 different 6 first digit combinations where the database has explicit entries for all 10 possible 7th digits has a wildcard/default entry also. Cleaning up all these will cut the database.csv size to 52% of its current size. Appended is a script to do that. Anyway, it seems like what lookup.sh should be doing is doing the 7 digit lookup like it does now, but if that doesn't match try a 6 digit lookup. Here's a script to clean up database.csv. The output is sorted by name not number, but a "sort -n" can fix that. #!/usr/bin/perl use strict; main(); sub main { my %db; my %wild; while (<>) { chomp; my($f3, $s3, $t1, @rest) = split /\|/; my $rest = join '|', @rest; my $key = "$f3|$s3|$rest"; if ($t1 eq '') { $wild{$key} = 1; } else { push @{$db{$key}}, $t1; } } foreach my $key (sort keys %db) { my($f3, $s3, @rest) = split /\|/, $key; my $rest = join '|', @rest; if ($wild{$key}) { print "$f3|$s3||$rest\n"; } else { if (10 == scalar(@{$db{$key}})) { print "$f3|$s3||$rest\n"; } else { foreach my $t1 (sort @{$db{$key}}) { print "$f3|$s3|$t1|$rest\n"; } } } } }
- Evidlo 4y agoThanks, I'll try it out.