Blocked IPs ... pipe to text file

Discuss suggestions and ideas for the forums, site, software.
Post Reply
najevi

Blocked IPs ... pipe to text file

Post by najevi »

qBittorrent v4.1.9

I will describe the analysis that I wish to do and how I hope to do it and then maybe a suggested feature will arise from any forum discussion that follows. It all hinges on the following question...

Q1. Where can I find a log file for the "Blocked IPs" tab?

I know that (on windows) a logfile (and a 16-deep backup archive) can be found at
%userprofile%\AppData\Local\qBittorrent\logs
however, that logfile is for the "Execution Log" -> "General" tab only.

The analysis I am interested in...

If I can parse the list of blocked IPs with something like gawk then I imagine building an associative array indexed by IP address that would yield a frequency distribution histogram or, perhaps more simply, a two column list that may then be sorted by frequency of block occurrence.

If I also parse the qBittorrent.ini file and specifically the list of user-banned IPs at

Code: Select all

[Preferences]
IPFilter\BannedIPs=
then I can imagine adding a third column to the above list which identifies those IP addresses that I have deliberately banned for whatever (?whimsical?) reason.

Slightly more adventurous (or even pie in the sky dreaming!) ... if I also parse my user-created blocklist.p2p file (your filename may be different as specified at Options -> Connection -> IP Filtering) ; then I could add a bit in that third column that distinguishes an I address blocked due to an address specified via my filter list. These filter lists allow for a range of IP addresses to be specified on one line; so searching for a match is probably not going to be a trivial exercise!

Even more adventurous (and quite possibly useless in the long run but nonetheless of interest while getting comfortable with the various sources of filter lists and ultimately settling upon what filter list sources give me the best piece of mind) would be to parse each source of that user-concatenated blocklist.p2p file to show me which lists are giving me frequent blocks versus only rare blocks.
  • To explain this last idea a little more clearly I need to describe for you how I periodically remake my ip filter list and the briefest way (and possibly helpful to forum readers) for me to describe this is to simply post my batch file...

Code: Select all

rem Update IP filter lists for qBittorrent

rem Make a sub-directory and work therein
cd "C:\Users\*USERNAME*\Downloads\00_ipfilter"

rem Backup old list
del blocklst.p2p.old
ren blocklst.p2p blocklst.p2p.old

rem Get the lists
set my_wget="C:\Program Files (x86)\GnuWin32\bin\wget"
%my_wget% http://list.iblocklist.com/?list=bt_bogon -O bog-z
%my_wget% http://list.iblocklist.com/?list=bt_level1 -O l1-z
%my_wget% http://list.iblocklist.com/?list=bt_level2 -O l2-z
%my_wget% http://list.iblocklist.com/?list=bt_level3 -O l3-z
%my_wget% http://list.iblocklist.com/?list=bt_rangetest -O rt-z
%my_wget% http://list.iblocklist.com/?list=bt_spyware -O spy-z
rem %my_wget% http://list.iblocklist.com/?list=bt_spider -O spi-z
%my_wget% http://list.iblocklist.com/?list=bt_ads -O ads-z
%my_wget% http://list.iblocklist.com/?list=bt_templist -O badp-z
%my_wget% http://list.iblocklist.com/?list=bt_hijacked -O hijack-z
%my_wget% http://list.iblocklist.com/?list=bt_dshield -O hack-z
%my_wget% http://list.iblocklist.com/?list=ijfqtofzixtwayqovmxn -O threat-z
%my_wget% http://list.iblocklist.com/?list=srzondksmjuwsvmgdbhi -O ainf-z
%my_wget% http://list.iblocklist.com/?list=lakuncfhfhgiqghqxjzi -O govt-z
%my_wget% http://list.iblocklist.com/?list=chykyvyiwrfszbqynhnd -O usgov-z
%my_wget% http://list.iblocklist.com/?list=xafnpguypyaewkmuugbd -O proxy-z

rem Merge the lists
type bog-z l1-z l2-z l3-z rt-z spy-z ads-z badp-z hijack-z hack-z threat-z ainf-z govt-z usgov-z proxy-z > blocklst.p2p.gz

rem Decompress
"C:\Program Files (x86)\GnuWin32\bin\gzip" -d -f blocklst.p2p.gz

rem Clean individual list files
rem del /f *-z

exit
  • I don't necessarily recommend others use this script as is because I suspect that some of the source lists I am currently using are overkill. So use your own discretion (level of paranoia!) if you leverage this script.
  • I also invite suggestions of other sources that are as easily accessible via wget.
Finally, through a process of elimination, any blocked IP that does not appear in either the user-ban list or the user-filter list would (?obviously?) be an IP address "auto-ban" generated by libtorrent due to that IP sending persistently bad packets ... n'est-ce pas?

So the third column of the abovementioned table/associative array might end up as either a single column with bit-wise meaning (per below) or perhaps one column per "source of ban"...

Code: Select all

0 = libtorrent auto-ban
1 = user ban list
2 = user filter list
4 = user source #1
8 = user source #2
16 = user source #3 ... etc.
... and yes, I do think it is necessary to allow for the possibility that the same IP address arises from multiple sources ... although, I cannot imagine how to explicitly identify a libtorrent autoban if that same address also appears in one of the other lists.

So there you have it! I doubt the above analysis of blocked IPs is of interest to more than a few percent of qBt users but the key enabling feature that I have so far failed to locate is some method of piping the output found at "Execution Log" -> "Blocked IPs" to a text file.
  1. For obvious reasons specifying an upper limit file size for such a log output would be appropriate.
  2. A back up archive similar to that currently used for qbittorrent.log.bak would also be desirable.
Any pointers/advice would be appreciated.
najevi

Re: Blocked IPs ... pipe to text file

Post by najevi »

In the process of trying to modify qBittorrent source code I discovered that multiple lines of the "Blocked IPs" log ought to be selectable ... and therefore copyable.

Selecting multiple lines in either of the two "Execution Log" tabs however, works a little differently than selecting multiple lines in either of the panels in the "Transfer" window. Before this realization I had resigned myself to the thought that only one line of log output could be selected at a time!

Shift+DownArrow or Shift+UpArrow selection do not work in either of the "Execution Log" tabs but Shift+LeftMouseClick does allow multiple rows of either "Blocked IPs" or "General" log output to be copied ... and subsequently pasted into a text file. Ctrl+A (and Ctrl+C) also work but you need to be a little patient for all lines of the log output to be selected and of course, the selection is outdated almost straight away if transfers are underway.

The above is a perfectly adequate method for getting to the raw data that I am interested in. .. No need to pipe Blocked IPs to a text file.
Post Reply