Bandwidth usage report per IP address

I created a simple python script for collecting data from mikrotik accounting (documetation) feature.

Here is my “mik_collector.py” script:

all you need to change is router_ip variable to match your router IP

after that you can run this script simply with this command:

python mik_collector.py

this will collect data from mikrotik every 5 seconds and store it in data.db sqlite3 database in the same directory as the script is.

All you need to do at mikrotik side is to enable accounting feature:

If you want to analyze your collected data you can do it with sqlite3 command from Ubuntu command prompt:

sqlite3 data.db "select * from sum_per_month order by month"

like this:

you can write your own queries, all data is stored in a table named accounting. You can share your query in the comments :)

Send telegram messages from Mikrotik RouterOS

If you are here you probably already know what telegram is. If not you can read about it here.

I created a simple script (SendToTelegram) that allows you to send messages to telegram:

:global telegramMessage
:local botid
:local chatid

set botid "sdfzgasf7126jwsd7a8s12>" # <- change this
set chatid "21156423187"            # <- change this

if ($telegramMessage != "") do={
   /tool fetch url="https://api.telegram.org/bot$botid/sendMessage\?chat_id=$chatid&text=$telegramMessage" keep-result=no
   set telegramMessage ""
}

Usage:

set your message to telegramMessage global variable

global telegramMessage "Wolfy was here"

run script

/system script run SendToTelegram

You can use this in combination with netwach:

you should recieve a message to your telegram :)

Programatically change ports on Mikrotik RouterOS

I created a simple script, that can help you change ports on your Mikrotik router

How to use

in my script fill array with port aliases:

:global PFVports {http="80";ssh="22";https="443";ftp=23};

add a comment to your NAT rule, that starts with “PFV_” and folows with port alias like that:

Now run my script and it will automatically set dst-port to whatever you set (in script) http port value… in my example port 80.

Next time you need to change some ports, you don’t need to change one by one, just update PFVports array and re-run this script.

Note:

dst-port is just one of many things that can be changed with this script… it can be easily changed to do whatever you need.

Hope you like it :)

BGInfo – Script for Local IP, Public IP and ISP Name

I recently created 3 scripts for BGInfo … If you need it, use it ;)

Local IP.vbs

I found this script at ardamis.com and adapted to my needs. I removed VMware local IP, because I don’t need it

strMsg = ""
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress,description from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")
 
For Each IPConfig in IPConfigSet
	If Not IsNull(IPConfig.IPAddress) Then
	For i = LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
		If Not Instr(IPConfig.IPAddress(i), ":") > 0 Then
			If InStr(1, IPConfig.description(i), "VMware") = 0 Then
				strMsg = strMsg & IPConfig.IPAddress(i)
				If i > 0 Then
					strMsg = strMsg & vbcrlf & VBTab
				End If
			End If
		End If
	Next
	End If
Next
Echo strMsg

Public IP.vbs

Based on script from howtogeek.com
I’m retrieving my public IP from ipify.org

Dim o
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "https://api.ipify.org", False
o.send
echo o.responseText

ISP Name.vbs

I’m using whoismyisp.org for this task

Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "https://www.whoismyisp.org", False
o.send
strid = o.responseText
Set myRegExp = New RegExp
With myRegExp
	.Pattern = "< p class=""isp"">(.*)< / p >" 'remove spaces before use :)
	.IgnoreCase = False
	.Global = False
End With
Set myMatches = myRegExp.Execute(strid)
 
Echo myMatches.Item(0).SubMatches(0)

IMPORTANT:
Because my regex contain HTML tags I added space between < and p. If you want to use my script remove this spaces!

Connectify Hotspot 2015

I was on vacation in Germany and as usually I carried my laptop, smartphone, iPad and other “Wi-Fi devices” with me…

When we arrived in hotel I asked for Wi-Fi access. They asked me for how many devices and I said that for 6 devices. After a while I received 6 tickets with 6 username/password… all different. I went to my room where I started connecting all devices to the hotel WiFi…

My phone and laptop connected without any problems, my wife phone couldn’t connect at all… in that moment I decided to check if is possible to share laptop internet with other devices and I found this simple, but powerful application… Connectify Hotspot … I instaled it, run it and in a few simple steps I configured it…

c3

After that, I connected all my devices to Wolfy-AP and everything works without problems. And the best thing off all… when I moved to the next hotel I asked only 1 ticket for WiFi, connected my laptop on hotel WiFi and without any other configuration all my other devices had internet connection, because they were already connected to my Wolfy-AP!

c2

I could write all features that comes with this great app, but I think that if you find that app useful, you will go on there homepage and get all information there…

I bought  Hotspot MAX version, witch have all features, but they have other version…

c4

The free version is good enough for travelers, but when you see how many problems go away with this app, you will probably decided to buy a licence just for support the developers even if you don’t need any other features :)

For aditional info go to www.connectify.me.

Do you already use connectify hotspot? Share your opinion with a comment :)

gmail configuration for Mikrotik router OS mail

Usually I would say something about the tool that I talk about, but this time a quote from wiki.mikrotik.com (link) will do the job:

E-mail tool is the utility that allows to send e-mails from the router. Tool can be used to send regular configuration backups and exports to network administrator.
Email tool uses only plain authentication and tls encryption. Other methods are not supported.

All data that you need is here:

Server:   74.125.136.108 [smtp.gmail.com] <- you can't use hostname
Port:     587
From:     <your name> <- nice name
User:     <gmail username> <- without @gmail.com
Password: <gmail password>

Configuring this tool is very simple, all you need to do is fill your data as shown in the picture

mail settings

or you can do this in one step from the terminal:

/tool e-mail set address=74.125.136.108 from="<your name>" password=<gmail password> port=587 start-tls=yes user=<gmail username>

This is all you need to do… next time I will write some usage example. If you have some your example, you can leave it in a comment ;)

Step by Step: How to configure a PPTP VPN Client on Mikrotik RouterOS

Intro

Last time I wrote how to configure a PPTP VPN Server on Mikrotik RouterOS

Today I will show you how to configure a PPTP VPN Client on Mikrotik RouterOS.

Before we start I will try to explain what I want to do…

My home network:

192.168.1.0/24 - Private
192.168.2.0/24 - Public

Remote location:

192.168.3.0/24

I would like to establish a VPN connection to the remote location on my Mikrotik router and allow computers (only!) from my private subnet to access computers on the remote location.

This tutorial will explain you how I did this. Here is a simple step by step tutorial with images and all information that you need to get PPTP VPN Client working…

Step 1: Create PPTP Client

Noting special on this step, so I think that the image is enough :)

slika 1

Step 2: Configure PPTP Client

After you created the PPTP Client you will need to enter some basic information:

  1. VPN server hostname or IP
  2. VPN username and password

slika 2

then you need a name for the client…

slika 3

If you enter the correct information you are already connected to the VPN server

You can now double-click on pptp-client and see the status

slika 4

Note

With the current configuration I can ping a remote computer from my Mikrotik:

[admin@MikroTik] > ping address=192.168.3.2 src-address=192.168.3.101 count=3 
HOST                                     SIZE TTL TIME  STATUS                                  
192.168.3.2                                56 127 42ms 
192.168.3.2                                56 127 44ms 
192.168.3.2                                56 127 41ms 
    sent=3 received=3 packet-loss=0% min-rtt=41ms avg-rtt=42ms max-rtt=44ms

but I can’t ping the same computer from any other location (other computers connected to my Mikrotik…

C:\Users\User>ping 192.168.3.2

Pinging 192.168.3.2 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.3.2:
    Packets: Sent = 3, Received = 0, Lost = 3 (100% loss)

to resolve this we need to add a NAT rule and one more route

Step 3: NAT configuration

[admin@MikroTik] > /ip firewall nat print
...

 1    ;;; pptp-client masquerade
      chain=srcnat action=masquerade src-address=192.168.1.2-192.168.1.254 
      out-interface=pptp-client log=no log-prefix="" 

...

slika 5

src-address is used to allow only computers from my private subnet

slika 6

In simple words… With this we allowed other computers to use VPN client interface.

Step 4: Add new route

route #4 is automatically added with pptp-client.
We need to add route #3…
Again… in simple words… With this route we route all request from 192.168.1.1 (router IP for private subnet) to remote subnet

[admin@MikroTik] > /ip route print 
 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 ...
 3 A S  192.168.3.0/24     192.168.1.1     pptp-client               1
 4 ADC  192.168.3.100/32   192.168.3.101   pptp-client               0
 ...

slika 7

Step 5: Finish

If you did all right, you now have access to the remote subnet from your private subnet.

A quick test…

C:\Users\User>ping 192.168.3.2
Pinging 192.168.3.2 with 32 bytes of data:
Reply from 192.168.3.2: bytes=32 time=41ms TTL=126
Reply from 192.168.3.2: bytes=32 time=41ms TTL=126
Reply from 192.168.3.2: bytes=32 time=86ms TTL=126

Ping statistics for 192.168.3.2:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 41ms, Maximum = 86ms, Average = 56ms

If you need any help or I did something wrong, leave a comment and I will try to do my best to help you.

Step by Step: How to configure a PPTP VPN Server on Mikrotik RouterOS

Intro

Before I started to wrote this post, I thought that would be nice to say some word about PPTP VPN and Mikrotik RouterOS, but then I realized that if you are reading this, there is no need to explain what is PPTP VPN server or Mikrotik RouterOS.

Here is a simple step by step tutorial with images and all information that you need to get a fully working PPTP VPN server… Continue reading Step by Step: How to configure a PPTP VPN Server on Mikrotik RouterOS

Cisco VPN client on Windows 8

I recently installed Cisco VPN client on Windows 8. Everything was OK until I tried to connect, than I was getting  this:

Error 442: Failed to Enable Virtual Adapter

To fix this you need to do this :

  1. Open Registry editor (Win + R, type “regedit”, return or run)
  2. Browse to the Registry Key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\CVirtA
  3. Select the DisplayName to modify
  4. Remove the leading characters from the value data upto “%;”
    • For x86 something like @oem8.inf,%CVirtA_Desc%;Cisco Systems VPN Adapter”
    • For x64 something like @oem8.inf,%CVirtA_Desc%;Cisco Systems VPN Adapter for 64-bit Windows”
  5. Try connecting again

I found the solution here.

Temporary Disabling Bash History

Let’s assume that you want execute some command that you don’t want in your history (e.g. commands with  passwords), but you don’t want to clear your entire history because of these.

all you need to do is to run the following command:

unset HISTFILE

or

HISTFILE=/dev/null

this will disable history for your current session.