|. : Local versus Abroad Traffic : .|
Today I needed to know how much traffic from a certain customer belongs to our country and how much traffic goes abroad. I use a Mikrotik as edge router for the customer and started to look in the forums if there is an example for this application (so that I won't have to use my brain *G*). After some browsing I found this article in the Mikrotik Wiki.
Seemed easy to me and after getting a list of IPs which are assigned to my country I generated a script and shot it into his router. It was succesfully loaded and the router started to count the local/abroad traffic. I got interessted and thought that there could be some cases where a script that automates this job would be handy. Well... below you can find my quick and dirty(!) hack.
The script asks for your TLD and your network. It will generate a file called localvsabroad.rsc that can simply be imported by executing an
"/import localvsabroad.rsc" (after uploading it to the router of coures ;-)
USE ON YOUR OWN RISK!
It does some marking according to the IP address list and adds two queues which display the amount of local/abroad traffic. You can also activate "Tools - Graphing" for a graphical analysis of the queues. This script DOES NOT any rate limiting! It's just for informational purposes about how much traffic is local and abroad, however it's very easy to activate rate limiting for the created queues.
So what are you waiting for? Gimme the damn code!
Q: Why would I need an automation?
A: Well, in most cases you might think you'll just need it once, but from my daily work I know that sometimes there are cases when you need to know how much traffic flows not just abroad, but to a certain country (for peering decisions etc). With some minor modifications you can use the script to show how much traffic flows to a selected country.
Q: How do I compile it?
A: *G* As every compiler would deny such an ugly code you just need to run "sh localvsabroad.sh" on your shell. In my case it's a FreeBSD 6.2 with csh.
Q: Any other requirements?
A: You need rsync to be installed, but I guess that's it. Well, yeah, an internet connection... ;-)
Q: How about CPU utilization?
A: In my case it increased about 10%. This depends on the length of the address list, the amount of traffic and, of course, your CPU. Just keep an eye on System - Resources.
Q: Anything else?
A: NO! It's already more explanation than code *G* No warranty, no support, just good luck ;-)