-
Notifications
You must be signed in to change notification settings - Fork 737
/
scan-and-livemon
executable file
·110 lines (92 loc) · 3.36 KB
/
scan-and-livemon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Author: Petter Reinholdtsen
# Contributor : Oros
# Lisence: GPL v2 or later at your own choice
"""
Script to scan for base stations and start submitt GSM packages on one
or more the frequencies found using grgsm_livemon_headless to the
loopback network device
The idea is to gather GSM packages from as many of the GSM base
stations and phones in the area as possible, by spreading across as
many operators as possible.
"""
import importlib.util
import importlib.machinery
from optparse import OptionParser
import subprocess
import sys
import distutils.spawn
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module
def find_gsm_bases():
grgsm_scanner_path = distutils.spawn.find_executable("grgsm_scanner")
if grgsm_scanner_path is None:
print("Error : Please install gr-gsm")
exit(1)
scanner = load_source('scanner', grgsm_scanner_path)
sys.modules['scanner'] = scanner
(options, args) = scanner.argument_parser().parse_args() #FIXME conflic with argument_parser line 93
list = scanner.do_scan(options.samp_rate, options.band, options.speed,
options.ppm, options.gain, options.args)
return list
def select_freqs(serverlist, count = 1):
"""
Select the requested number of frequencies, spread across as many base
station operators (mcc+mnc) as possible, pick the ones with the
strongest signals.
Could consider arfcn, freq, cid, lac, mcc, mnc, ccch_conf, power,
neighbours, cell_arfcns to get as wide spread as possible, but is
only using mcc, mnc and power at the moment.
"""
# Make shallow copy to avoid modifying the list of the caller when
# removing elements below.
listcopy = []
for s in serverlist:
listcopy.append(s)
freqs = []
sorted_list = sorted(listcopy, key=lambda s:(-s.power, s.mcc, s.mnc))
for s in sorted_list:
if count > 0:
freqs.append(s.freq)
else:
break
count = count - 1
return freqs
def argument_parser():
parser = OptionParser(usage="%prog: [options]")
parser.add_option("-n", "--numrecv", dest="numrecv", type="int",
default=1,
help="Set number of livemon processes to start (use one per receiver) [default=%default]")
return parser
def main(options = None):
if options is None:
(options, args) = argument_parser().parse_args()
print("Locating potential GSM base station frequencies (this can take a few minutes).")
list = find_gsm_bases()
print("Found %d frequences" % len(list))
if len(list) > 0:
numreceivers = options.numrecv
freqs = select_freqs(list, numreceivers)
print("Listening on the frequencies for %d potential GSM base stations." % numreceivers)
# Make sure a user process can listen on port 4729 by asking
# livemon processes to listen on other ports.
serverport = 4730
procs = []
for freq in freqs:
print("Starting livemon for freqency %.0f, server on port %d" % (freq, serverport))
proc = subprocess.Popen(["grgsm_livemon_headless",
"--serverport=%d" % serverport,
"-f", str(freq)])
procs.append(proc)
serverport = serverport + 1
# Keep the processes in our process group, to make sure they all die when scan-and-livemon is killed
for proc in procs:
proc.wait()
if __name__ == '__main__':
main()