Python Forum
Redirection giving faulty results - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Redirection giving faulty results (/thread-28429.html)



Redirection giving faulty results - monstrup - Jul-18-2020

Hey all. I am working on detectors of fake BTSes. Ive set up my fake BTS using yateBTS and its up and running. Now, I intent to catch the fake BTS so that an alarm can be generated everytime there is a rogue BTS in the locality. I am using the grgsm project by ptrkrysik (available on gitbub). I used a bladeRFx115 for the fake BTS setup and am using a simple RTL-SDR for catching the fake BTS. Now, as of present, I am writing a script so that a click of the button on my Tkinter GUI can run the grgsm scan (python command: grgsm_scanner) and also convert the output displayed on terminal window into a text file so that that text file can be used to compare it to a database text file and the BTS with different parameters than the already verified genuine BTS parameters can be separated for further tests. My problem, presently, is that once i run the scanner on its own or on the script (without converting the output to the text file), the result is just fine.
Output:
*/\*/\*/\*/\*/\*/\*/\*/\* |g|r|g|s|m|s|c|a|n|n|e|r| *\/*\/*\/*\/*\/*\/*\/*\/* Available GSM Frequencies linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown ARFCN: 987, Freq: 927.6M, CID: 36233, LAC: 7713, MCC: 410, MNC: 4, Pwr: -47 ARFCN: 1004, Freq: 931.0M, CID: 36231, LAC: 7713, MCC: 410, MNC: 4, Pwr: -31 ARFCN: 1008, Freq: 931.8M, CID: 47103, LAC: 7713, MCC: 410, MNC: 4, Pwr: -37 ARFCN: 6, Freq: 936.2M, CID: 10096, LAC: 10470, MCC: 410, MNC: 1, Pwr: -27 ARFCN: 10, Freq: 937.0M, CID: 30911, LAC: 10470, MCC: 410, MNC: 1, Pwr: -28 ARFCN: 49, Freq: 944.8M, CID: 15535, LAC: 52207, MCC: 410, MNC: 3, Pwr: -36 ARFCN: 62, Freq: 947.4M, CID: 32941, LAC: 51136, MCC: 410, MNC: 3, Pwr: -41 ARFCN: 66, Freq: 948.2M, CID: 10001, LAC: 470, MCC: 410, MNC: 6, Pwr: -28 ARFCN: 79, Freq: 950.8M, CID: 10003, LAC: 470, MCC: 410, MNC: 6, Pwr: -48 ARFCN: 82, Freq: 951.4M, CID: 10002, LAC: 470, MCC: 410, MNC: 6, Pwr: -40 ARFCN: 100, Freq: 955.0M, CID: 667, LAC: 1007, MCC: 410, MNC: 3, Pwr: -27 The scan GSM frequencies are collected DONE!
However, once I write the redirection character
 #! /bin/sh
clear
echo "                      */\*/\*/\*/\*/\*/\*/\*/\* "
echo "                      |g|r|g|s|m|s|c|a|n|n|e|r| "
echo "                      *\/*\/*\/*\/*\/*\/*\/*\/* "
echo

echo "Available GSM Frequencies"
grgsm_scanner > alpha.txt


echo "The scan GSM frequencies are collected"
notify-send "COLLECTED!"
echo DONE!
the output is a blank screen
Output:
*/\*/\*/\*/\*/\*/\*/\*/\* |g|r|g|s|m|s|c|a|n|n|e|r| *\/*\/*\/*\/*\/*\/*\/*\/* Available GSM Frequencies The scan GSM frequencies are collected DONE!
I've tried this over and over but no avail. Please help.
Further more, my database text file has data in the following way:
ARFCN: 987, Freq: 927.6M, CID: 36233, LAC: 7713, MCC: 410, MNC: 4, Pwr: -37
ARFCN: 989, Freq: 928.0M, CID: 57501, LAC: 7716, MCC: 410, MNC: 4, Pwr: -45
ARFCN: 992, Freq: 928.6M, CID: 58531, LAC: 7716, MCC: 410, MNC: 4, Pwr: -42
ARFCN: 994, Freq: 929.0M, CID: 36231, LAC: 7713, MCC: 410, MNC: 4, Pwr: -31
ARFCN: 995, Freq: 929.2M, CID: 36232, LAC: 7713, MCC: 410, MNC: 4, Pwr: -39
ARFCN: 999, Freq: 930.0M, CID: 47081, LAC: 7716, MCC: 410, MNC: 4, Pwr: -36
ARFCN: 1004, Freq: 931.0M, CID: 36231, LAC: 7713, MCC: 410, MNC: 4, Pwr: -31
ARFCN: 1008, Freq: 931.8M, CID: 47103, LAC: 7713, MCC: 410, MNC: 4, Pwr: -37
ARFCN: 1010, Freq: 932.2M, CID: 40691, LAC: 7716, MCC: 410, MNC: 4, Pwr: -48
ARFCN: 1011, Freq: 932.4M, CID: 47102, LAC: 7713, MCC: 410, MNC: 4, Pwr: -50
ARFCN: 1, Freq: 935.2M, CID: 13013, LAC: 10421, MCC: 410, MNC: 1, Pwr: -65
ARFCN: 2, Freq: 935.4M, CID: 30889, LAC: 10421, MCC: 410, MNC: 1, Pwr: -60
ARFCN: 3, Freq: 935.6M, CID: 30928, LAC: 10470, MCC: 410, MNC: 1, Pwr: -45
ARFCN: 3, Freq: 935.6M, CID: 33272, LAC: 10421, MCC: 410, MNC: 1, Pwr: -65
ARFCN: 6, Freq: 936.2M, CID: 10096, LAC: 10470, MCC: 410, MNC: 1, Pwr: -27
ARFCN: 10, Freq: 937.0M, CID: 30911, LAC: 10470, MCC: 410, MNC: 1, Pwr: -47
ARFCN: 25, Freq: 940.0M, CID: 14429, LAC: 51136, MCC: 410, MNC: 3, Pwr: -44
ARFCN: 49, Freq: 944.8M, CID: 15535, LAC: 52207, MCC: 410, MNC: 3, Pwr: -27
ARFCN: 51, Freq: 945.2M, CID: 12408, LAC: 51136, MCC: 410, MNC: 3, Pwr: -46
ARFCN: 54, Freq: 945.8M, CID: 35535, LAC: 52207, MCC: 410, MNC: 3, Pwr: -49
ARFCN: 56, Freq: 946.2M, CID: 25535, LAC: 52207, MCC: 410, MNC: 3, Pwr: -51
ARFCN: 58, Freq: 946.6M, CID: 12941, LAC: 51136, MCC: 410, MNC: 3, Pwr: -35
ARFCN: 60, Freq: 947.0M, CID: 18662, LAC: 51136, MCC: 410, MNC: 3, Pwr: -58
ARFCN: 62, Freq: 947.4M, CID: 32941, LAC: 51136, MCC: 410, MNC: 3, Pwr: -52
ARFCN: 64, Freq: 947.8M, CID: 7673, LAC: 470, MCC: 410, MNC: 6, Pwr: -43
ARFCN: 66, Freq: 948.2M, CID: 10001, LAC: 470, MCC: 410, MNC: 6, Pwr: -27
ARFCN: 68, Freq: 948.6M, CID: 12941, LAC: 51136, MCC: 410, MNC: 3, Pwr: -50
ARFCN: 70, Freq: 949.0M, CID: 15132, LAC: 470, MCC: 410, MNC: 6, Pwr: -34
ARFCN: 71, Freq: 949.2M, CID: 5373, LAC: 470, MCC: 410, MNC: 6, Pwr: -44
ARFCN: 75, Freq: 950.0M, CID: 6561, LAC: 470, MCC: 410, MNC: 6, Pwr: -45
ARFCN: 79, Freq: 950.8M, CID: 10003, LAC: 470, MCC: 410, MNC: 6, Pwr: -48
ARFCN: 82, Freq: 951.4M, CID: 10002, LAC: 470, MCC: 410, MNC: 6, Pwr: -34
ARFCN: 86, Freq: 952.2M, CID: 0, LAC: 470, MCC: 410, MNC: 6, Pwr: -57
ARFCN: 117, Freq: 958.4M, CID: 20096, LAC: 10470, MCC: 410, MNC: 1, Pwr: -28
ARFCN: 119, Freq: 958.8M, CID: 12549, LAC: 10470, MCC: 410, MNC: 1, Pwr: -41
ARFCN: 120, Freq: 959.0M, CID: 30096, LAC: 10470, MCC: 410, MNC: 1, Pwr: -31
ARFCN: 122, Freq: 959.4M, CID: 33783, LAC: 10421, MCC: 410, MNC: 1, Pwr: -42
ARFCN: 124, Freq: 959.8M, CID: 42549, LAC: 10470, MCC: 410, MNC: 1, Pwr: -33

The output after converted to text file has to be compared with this such that even if a single parameter (except the power) differs, it keeps that tower aside for further tests. Kindly guide me how to write a code to compare the two. It would be greatly appreciated if each column in my output file is compared to each column of my database (like the ARFCN values from my output are first compared to the ARFCN values in the database and then the frequencies and onwards). I wish to remove the power field altogether from my database as well as output.
Thanks

PS. I am using ubuntu 18.04 LTS operating system'


RE: Redirection giving faulty results - Gribouillis - Jul-18-2020

You could perhaps try
Output:
grgsm_scanner | tee alpha.txt
for the first question.


RE: Redirection giving faulty results - monstrup - Jul-18-2020

(Jul-18-2020, 10:00 PM)Gribouillis Wrote: You could perhaps try
Output:
grgsm_scanner | tee alpha.txt
for the first question.

#! /bin/sh
clear
echo "                      */\*/\*/\*/\*/\*/\*/\*/\* "
echo "                      |g|r|g|s|m|s|c|a|n|n|e|r| "
echo "                      *\/*\/*\/*\/*\/*\/*\/*\/* "
echo

echo "Available GSM Frequencies"

grgsm_scanner | tee alpha.txt


echo "The scan GSM frequencies are collected"
notify-send "COLLECTED!"
echo DONE!
Ive tried this too. yet the output is just the same- blank.
Output:
*/\*/\*/\*/\*/\*/\*/\*/\* |g|r|g|s|m|s|c|a|n|n|e|r| *\/*\/*\/*\/*\/*\/*\/*\/* Available GSM Frequencies linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown The scan GSM frequencies are collected DONE!
The alpha.txt file looks like this:
Output:
linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown



RE: Redirection giving faulty results - Gribouillis - Jul-19-2020

Then you can perhaps try
Output:
script --return --quiet -c "grgsm_scanner" alpha.txt
or
Output:
script --return --quiet -c "grgsm_scanner | tee alpha.txt" /dev/null
to let the program think that is is being called from a terminal instead of a shell script.


RE: Redirection giving faulty results - monstrup - Jul-19-2020

(Jul-19-2020, 05:51 AM)Gribouillis Wrote: Then you can perhaps try
Output:
script --return --quiet -c "grgsm_scanner" alpha.txt
or
Output:
script --return --quiet -c "grgsm_scanner | tee alpha.txt" /dev/null
to let the program think that is is being called from a terminal instead of a shell script.

The first method is working for me. Thankyou so much.
Output:
Script started on 2020-07-19 11:26:36+0500 linux; GNU C++ version 7.3.0; Boost_106501; UHD_003.010.003.000-0-unknown ARFCN: 1004, Freq: 931.0M, CID: 36231, LAC: 7713, MCC: 410, MNC: 4, Pwr: -46 ARFCN: 1008, Freq: 931.8M, CID: 47103, LAC: 7713, MCC: 410, MNC: 4, Pwr: -34 ARFCN: 6, Freq: 936.2M, CID: 10096, LAC: 10470, MCC: 410, MNC: 1, Pwr: -27 ARFCN: 10, Freq: 937.0M, CID: 30911, LAC: 10470, MCC: 410, MNC: 1, Pwr: -38 ARFCN: 49, Freq: 944.8M, CID: 15535, LAC: 52207, MCC: 410, MNC: 3, Pwr: -28 ARFCN: 66, Freq: 948.2M, CID: 10001, LAC: 470, MCC: 410, MNC: 6, Pwr: -28 ARFCN: 75, Freq: 950.0M, CID: 6561, LAC: 470, MCC: 410, MNC: 6, Pwr: -47 ARFCN: 79, Freq: 950.8M, CID: 10003, LAC: 470, MCC: 410, MNC: 6, Pwr: -48 ARFCN: 82, Freq: 951.4M, CID: 10002, LAC: 470, MCC: 410, MNC: 6, Pwr: -39 Script done on 2020-07-19 11:29:22+0500
This is the text file.
If you can guide me about me second issue, i'll be very grateful. I need to compare this text file to another database text file but this has to be done column wise. Like first all the ARFCNs compared with the ARFCNs in my database and so on. Is there anyway i can do this?
Thanks in advance.


RE: Redirection giving faulty results - Gribouillis - Jul-19-2020

What have you tried? This is a python forum and until now, we have not seen a single line of python in this thread! Or perhaps you want to post in the job offers forum?