Automating BitTorrent traffic detection via bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating BitTorrent traffic detection via bash
# 1  
Old 06-09-2018
Hammer & Screwdriver Automating BitTorrent traffic detection via bash

Hi all,

Earlier today, I read an article on how to detect BitTorrent traffic using tshark (the cli version of Wireshark).

I wanted to have a go at creating a simple script, that when BitTorrent packets are detected the network connection will be throttled. The thing is that I am not great at bash scripting and would like some assistance with my script (see below).
Code:
#!/bin/bash
# Sample network stream for 10 seconds and filter for uTP and/or BitTorrent traffic that does not originate on port 80 (HTTP), 443 (HTTPS), 22 (SSH)
TSOUTPUT=$(sudo tshark -a "duration:10" -Y 'udp[8:5] == "\x64\x32\x3A\x69\x70" or bittorrent' -f 'not port 80 and not port 22 and not port 443')

# Get the output of running the tshark command
if [[ $TSOUTPUT != "0 packets captured" ]] then
	# BitTorrent detected - slow down upload/download speed to 0.5 Mbps
	wondershaper eth0 512 512
else
	# Not BitTorrent detected - reset any previously throttled speeds back to full speed
	wondershaper clear eth0
fi

The bash script should be designed to run in cron every minute or two.

I really would appreciate any help with this.
# 2  
Old 06-10-2018
I'm not really familiar with tshark or wondershaper so I've commented them and replaced with a testing string that you can edit/test to get the functionality of your bash script proven.

Have a play around with this (you should be able to run it directly from a bash login):

Code:
#!/bin/bash
# Sample network stream for 10 seconds and filter for uTP and/or BitTorrent traffic that does not originate on port 80 (HTTP), 443 (HTTPS), 22 (SSH)
# TSOUTPUT=$(sudo tshark -a "duration:10" -Y 'udp[8:5] == "\x64\x32\x3A\x69\x70" or bittorrent' -f 'not port 80 and not port 22 and not port 443')
TSOUTPUT="some random output

Result: 10 packets captured
done"

# Get the output of running the tshark command
if [[ $TSOUTPUT =~ " 0 packets captured" ]]
then
        # No BitTorrent detected - reset any previously throttled speeds back to full speed
        #wondershaper clear eth0
    echo "None Found - unshape"
else
        # BitTorrent detected - slow down upload/download speed to 0.5 Mbps
        # wondershaper eth0 512 512
    echo "Found traffic - shape connection now"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with automating a bash script

Hi Guys, There are some emails going deferred as we got some new IP's from our ISP. So I was trying to manually copy the deferred mail and forward it to our sales team so that they can contact our client. I am new to this script thing, but luckily I was able to write the code to extract the data... (1 Reply)
Discussion started by: linuxrulz
1 Replies

2. Programming

Parallel Processing Detection and Program Return Value Detection

Hey, for the purpose of a research project I need to know if a specific type of parallel processing is being utilized by any user-run programs. Is there a way to detect whether a program either returns a value to another program at the end of execution, or just utilizes any form of parallel... (4 Replies)
Discussion started by: azar.zorn
4 Replies

3. Shell Programming and Scripting

need bash script Intrusion Detection on Linux

Hello all I have a script but I failed on the creation of Script is any is carried out in the shell sends the owner of the server, the message is has been implemented For example, functioned as a detection system intruders but in smaller Is it possible to help if you allow I want the... (4 Replies)
Discussion started by: x-zer0
4 Replies

4. Programming

Bittorrent program

Hi everyone, I'm trying to replicate a bittorrent program using Linux client/server programming. I have a few questions on how to approach this.. 1) If I write a client/server program, can it be merged together? Usually bittorrent programs can send/receive files 2) Doing it step by step, I... (1 Reply)
Discussion started by: Shiroi98
1 Replies

5. IP Networking

Unknown open port: "6881/tcp open bittorrent-tracker" found with nmap

Hi. I ran nmap on my server, and I get the following: Starting Nmap 4.76 ( http://nmap.org ) at 2009-03-19 16:33 EDT Interesting ports on -------- (-----): Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 6881/tcp open bittorrent-tracker The... (0 Replies)
Discussion started by: Rledley
0 Replies

6. UNIX for Dummies Questions & Answers

Bittorrent over SSH

Hi, I'm behind a university firewall where nearly all ports are blocked. Therefore I've set up a ssh tunnel to my comp at home so that I can bypass the uni firewall and use bittorrent. I used mainly these 3 guides to setup the tunnel: http://freebsdcluster.org/~lasse/sshazureustunnel/ , Whalesalad... (1 Reply)
Discussion started by: bizso
1 Replies

7. IP Networking

modem detection

How to get information that where is my modem configured in /dev. I have two modems configured in my device .. one is USB and other is PCI modem.. USB is detected as /dev/USB0. but how to see about PCI modem? (0 Replies)
Discussion started by: s123.radha
0 Replies
Login or Register to Ask a Question