Kau bisa bersembunyi dari kesalahanmu, tapi tidak dari penyesalanmu. Kau bisa bermain dengan dramamu, tapi tidak dengan karmamu.

  • About

    Seorang Teknisi Jaringan yang pernah berkecimpung di Internet Service Provider (ISP) dan akhirnya memutuskan diri untuk menjadi freelancer yang berdomisili di Solo, Surakarta Hadiningrat.

  • Services

    Melayani jasa pasang Internet berbasis Wireless maupun Fiber Optic, Jasa Pasang Tower/Pipa, Pointing Wireless, Setting Router, CCTV, Hotspot, Proxy, Web Server, Network Managed dan Monitoring

  • Contact

    Berbagai saran, kritikan, keluhan dan masukan akan sangat berarti bagi saya. Anda dapat menghubungi/whatsapp saya di nomor:08564-212-8686 atau melalui BBM:2128686

    Showing posts with label Mikrotik. Show all posts
    Showing posts with label Mikrotik. Show all posts

    Sunday, January 10, 2021

    Dear all,

    Jumpa lagi sama saya. Kali ini saya akan bagi tips untuk membuat link aggregate BGP menggunakan Juniper Feat Mikrotik, dimana ada 2 link metro-e yakni ICONPLUS dan HSP

    Berikut skema-nya :

    [IDC3D] Juniper <> metro-e ICON <> Mikrotik sisi pelanggan
    [IDC3D] Juniper <> metro-e HSP <> Mikrotik sisi pelanggan

    dimana ip point to point-nya

    Juniper 10.0.101.17/30 <> 10.0.101.18/30 Mikrotik
    Juniper 10.0.101.21/30 <> 10.0.101.22/30 Mikrotik

    OK, sekarang kita set di sisi Junipernya

    Kita buat dulu policy LOADBALANCE

    # set policy-options policy-statement LOADBALANCE then load-balance consistent-hash

    nanti hasilnya gini

    policy-statement LOADBALANCE {

        then {

            load-balance consistent-hash;

        }

    }

     

    terus sekarang bikin policy routing filter IN

    # top show policy-options policy-statement DIST-MIRZA-IN

    inactive: term REJECT-TMP {

        then reject;

    }

    term ACCEPT {

        from {

            route-filter 103.146.184.0/23 prefix-length-range /25-/32;

            route-filter 129.9.0.0/16 prefix-length-range /16-/32;

        }

        then accept;

    }

    term REJECT {

        then reject;

    }


    lalu buat policy routing filter OUT

    # top show policy-options policy-statement DIST-MIRZA-OUT

    inactive: term REJECT-TMP {

        then reject;

    }

    term HSP {

        from {

            route-filter 0.0.0.0/0 exact;

        }

        then {

            next-hop 10.0.101.17;

            accept;

        }

    }

    term ICON {

        from {

            route-filter 0.0.0.0/0 exact;

        }

        then {

            next-hop 10.0.101.21;

            accept;

        }

    }

    inactive: term ACCEPT {

        from {

            route-filter 0.0.0.0/0 exact;

        }

        then accept;

    }

    term REJECT {

        then reject;

    }

    Jika sudah, lalu buat bgp peer neighbor

    group MIRZA {

        description Mirza;

        import DIST-MIRZA-IN;

        export DIST-MIRZA-OUT;

        peer-as 65530;

        multipath;

        neighbor 10.0.101.22;

        neighbor 10.0.101.18;

        neighbor 10.0.101.26;

    }

    kemudian cek confignya sudah bener apa belum
    CoreBorder# commit check
    CoreBorder# commit confirm 5 <= masa berlaku 5 menit, bebas silahkan tentukan
    misal sudah ok tinggal gini
    CoreBorder# commit

    Lalu untuk sisi Mikrotiknya setingan BGP Standar, ngga ada setingan khusus.

    Semoga Bermanfaat

    Saturday, August 8, 2020

    :global identity [/system identity get name ]

    :global perulangan

    :global statusEth

    :global iface "ether1"


    /int eth monitor $iface once do={

       :if ($"rate" = "100Mbps") do={:set statusEth 0; :set perulangan ($perulangan +1)}

       :if ($"rate" = "100Mbps" && $perulangan =3) do={

           :local pesan "[$identity] %0A$iface = 100Mbps"

           :log error "$iface 100Mbps";

           /tool fetch url="https://api.telegram.org/bot380921546:AAFNlaaxhI063wPAZC-3oNJlefBHz3XgyfI/sendMessage?chat_id=-203533762&text=$pesan" keep-result=no

           /tool fetch url="https://api.telegram.org/bot478500121:AAGnvRMmFHjV25Otf-iUbuN9R1RwjAAM5s8/sendMessage?chat_id=445109932&text=$pesan" keep-result=no

           }

       :if ($"rate" = "1Gbps") do={:set statusEth 1; :set perulangan ($perulangan +1)}

       :if ($"rate" = "1Gbps" && $perulangan =3) do={

           :local pesan "[$identity] %0A$iface = 1Gbps"

           :log warning "$iface 1Gbps"

           /tool fetch url="https://api.telegram.org/bot380921546:AAFNlaaxhI063wPAZC-3oNJlefBHz3XgyfI/sendMessage?chat_id=-203533762&text=$pesan" keep-result=no

           /tool fetch url="https://api.telegram.org/bot478500121:AAGnvRMmFHjV25Otf-iUbuN9R1RwjAAM5s8/sendMessage?chat_id=445109932&text=$pesan" keep-result=no

           }

       :if ($perulangan = 1000 && $statusEth =0 ) do={

           :local pesan "[$identity] %0ACuma Ngabari aja boss%0A$iface = 100Mbps"

           :log warning "Cuma Ngabari, $iface = 100Mbps"

           /tool fetch url="https://api.telegram.org/bot380921546:AAFNlaaxhI063wPAZC-3oNJlefBHz3XgyfI/sendMessage?chat_id=-203533762&text=$pesan" keep-result=no

           /tool fetch url="https://api.telegram.org/bot478500121:AAGnvRMmFHjV25Otf-iUbuN9R1RwjAAM5s8/sendMessage?chat_id=445109932&text=$pesan" keep-result=no

           :set perulangan 1

           }

       }


    Tuesday, July 21, 2020

    :global iface ether5.WAN-ISP
    :global trafikawal
    :global trafik
    # reset tanggal 1
    #/system ntp client set primary-ntp=[:resolve id.pool.ntp.org] enabled=yes
    #/system clock set time-zone-name="Asia/Jakarta"
    :local date [/system clock get date]
    :local tanggal [ :pick $date 4 6 ]
    #:log warning $tanggal
    :if ($tanggal = 1) do={:set trafikawal 0}
    :set trafikawal [/interface get [find name=$iface] rx-byte]
    :if ($trafikawal > 1073741824) do={
    :set trafik ($trafikawal / 1073741824)
    :set trafik ($trafik." GB")
    } else={
    :set trafik ($trafikawal / 1048576)
    :set trafik ($trafik." MB")
    }
    :log warning "trafik $iface = $trafik"
    /in ethernet set $iface comment="$trafikawal"

    Tuesday, May 5, 2020

    :global currentIP
    # ubah di sini
    :global iface "PPPOE"
    /in pppoe-client monitor $iface once do={:set currentIP $"local-address" }
    :if ($currentIP in 10.0.0.0/8) do={
    :log error "re-dial...";
    /in pppoe-client disable $iface
    :delay 2
    /in pppoe-client enable $iface
    }
    # ubah di sini
    :global ifacegre "gre-dewo"
    :global p2p [/ip address get [find interface=$ifacegre] network  ]
    :global target [/in gre get $ifacegre remote-address ]
    # cek berdasarkan running interface gre
    #:if ($statusgre != true) do={
    #/in gre export file=$ifacegre
    #:delay 1
    # cek berdasarkan ping target
    :if ([/ping $p2p count=2] = 0 ) do={
    /in gre export file=$ifacegre
    :delay 1
    /in gre set $ifacegre local-address=$currentIP
    :log error "$ifacegre error, kirim file"
    /file set contents="/in gre set $ifacegre remote-address=$currentIP" [find name~"$ifacegre"]
    :delay 2
    /tool fetch mode=ftp upload=yes src-path="$ifacegre.rsc" dst-path="$ifacegre.rsc" user=ftp password=ftp port=21 address="$target"
    }

    Sunday, April 5, 2020

    OK, kali ini saya akan share script mentah untuk update ip list yang nantinya bikin script lagi buat dijalanin di mikrotik.

    #!/bin/bash
    wget -O all.txt https://lists.blocklist.de/lists/all.txt
    sleep 2
    rm -rf blocked.rsc
    touch blocked.rsc
    DATE=$(date '+%d/%m/%Y %H:%M:%S')
    LINE=$(wc -l all.txt | awk '{print $1}')
    echo -e "# Generated at $DATE ... $LINE lines\n# Sumber: https://lists.blocklist.de/lists/all.txt\n# Silahkan bisa ditambahkan di router masing-masing\n# Supported by: https://yam.net.id\n\n# Add scheduler\n:if ([:len [/system scheduler find name=\"autoupdate\"]]=0) do={\n/system scheduler add name=autoupdate on-event=\"/tool fetch url=http://103.146.184.12/dump/blocked.rsc;:delay 1;/import blocked.rsc\" interval=\"2d 00:00:00\" start-time=04:00:00}\n\n# Start blocking now\n:if ([:len [/ip fi fi find comment=BLOCKED]]=0) do={\n/ip fi fi add chain=input src-address-list=BLOCKED protocol=udp dst-port=!80,443 action=drop comment=BLOCKED\n/ip fi fi add chain=input src-address-list=BLOCKED protocol=tcp dst-port=!80,443 action=reject reject-with=icmp-network-unreachable comment=BLOCKED\n/ip fi fi add chain=forward src-address-list=BLOCKED protocol=tcp dst-port=!80,443 action=reject reject-with=icmp-network-unreachable comment=BLOCKED\n/ip fi fi add chain=forward src-address-list=BLOCKED protocol=udp dst-port=!80,443 action=drop comment=BLOCKED}\n\n# Clearing address-list\n/ip firewall address-list\nadd list=BLOCKED address=1.2.3.4\nremove [find list=BLOCKED]\n# Kasih jeda\n:delay 2\n" > blocked.rsc
    cat all.txt | grep "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]$" | awk '{print "/ip firewall address-list add list=BLOCKED address="$1 }' >> blocked.rsc

    
    
    
    
    reference :
    https://deadc0de.re/articles/unbound-blocking-ads.html

    Download the list you're interested to block (for example ads+malwares+social networks)
    $ wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/social/hosts
    
    Entries in the host file are in the form 0.0.0.0 <domain> and unbound needs something like this:
    local-zone: "<domain>" redirect
    local-data: "<domain> A 0.0.0.0"
    
    Following awk command will transform the list into something that unbound understands:
    $ cat hosts | grep '^0\.0\.0\.0' | awk '{print "local-zone: \""$2"\" redirect\nlocal-data: \""$2" A 0.0.0.0\""}' > ads.conf 
    Finally copy the resulting file to pfsense (or to your DNS resolver running unbound).

    Saturday, February 22, 2020

    Hi Brian,
    Can you explain the easiest way to construct a regular expression in BGP?
    Thanks,
    Rowan
    Hi Rowan,
    Regular expressions are strings of special characters that can be used to search and find character patterns. Within the scope of BGP in Cisco IOS regular expressions can be used in show commands and AS-Path access-lists to match BGP prefixes based on the information contained in their AS-Path.
    In order to understand how to build regular expressions we first need to know what the character definitions are for the regex function of IOS. The below table illustrates the regex characters and their usage. This information is contained in the Cisco IOS documentation under the Appendix of Cisco IOS Terminal Services Configuration Guide, Release 12.2.
    +------------------------------------------------------+
    
    | CHAR | USAGE                                         |
    
    +------------------------------------------------------|
    
    |  ^   | Start of string                               |
    
    |------|-----------------------------------------------|
    
    |  $   | End of string                                 |
    
    |------|-----------------------------------------------|
    
    |  []  | Range of characters                           |
    
    |------|-----------------------------------------------|
    
    |  -   | Used to specify range ( i.e. [0-9] )          |
    
    |------|-----------------------------------------------|
    
    |  ( ) | Logical grouping                              |
    
    |------|-----------------------------------------------|
    
    |  .   | Any single character                          |
    
    |------|-----------------------------------------------|
    
    |  *   | Zero or more instances                        |
    
    |------|-----------------------------------------------|
    
    |  +   | One or more instance                          |
    
    |------|-----------------------------------------------|
    
    |  ?   | Zero or one instance                          |
    
    |------|-----------------------------------------------|
    
    |  _   | Comma, open or close brace, open or close     |
    
    |      | parentheses, start or end of string, or space |
    
    +------------------------------------------------------+
    
    Some commonly used regular expressions include:
    +-------------+---------------------------+
    
    | Expression  | Meaning                   |
    
    |-------------+---------------------------|
    
    | .*          | Anything                  |
    
    |-------------+---------------------------|
    
    | ^$          | Locally originated routes |
    
    |-------------+---------------------------|
    
    | ^100_       | Learned from AS 100       |
    
    |-------------+---------------------------|
    
    | _100$       | Originated in AS 100      |
    
    |-------------+---------------------------|
    
    | _100_       | Any instance of AS 100    |
    
    |-------------+---------------------------|
    
    | ^[0-9]+$    | Directly connected ASes   |
    
    +-------------+---------------------------+
    
    Let’s break some of the above expressions down step-by-step. The first one “.*” says to match any single character (“.”), and then find zero or more instances of that single character (“*”). This means zero or more instances or any character, which effectively means anything.
    The next string “^$” says to match the beginning of the string (“^”), and then immediately match the end of the string (“$”). This means that the string is null. Within the scope of BGP the only time that the AS-Path is null is when you are looking at a route within your own AS that you or one of your iBGP peers has originated. Hence this matches locally originated routes.
    The next string “^100_” says to match the beginning of the string (“^”), the literal characters 100, and then a comma, an open or close brace, an open or close, a parentheses, the start or end of the string, or a space (“_”). This means that the string must start with the number 100 followed by any non-alphanumeric character. In the scope of BGP this means that routes which are learned from the AS 100 will be matched, as 100 will be the first AS in the path when AS 100 is sending us routes.
    The next string “_100$” is the exact opposite of the previous one. This string says to start with any non-alphanumeric character (“_”), followed by the literal characters 100, followed by the end of the string (“$”). This means that AS 100 is the last AS in the path, or in other words that the prefix in question was originated by AS 100.
    The next string “_100_” is the combination of the two previous strings with some extra matches. This string means that the literal characters 100 are set between any two non-alphanumeric characters. The first of these could be the start of the string, which would match routes learned from AS 100, while the second of these could be the end of the string, which would match routes originated in AS 100. Another case could be that the underscores represent spaces, in which the string would match any other AS path information as long as “ 100 ” is included somewhere. This would match any routes which transit AS 100, and therefore “_ASN_” is generally meant to match routes that transit a particular AS as defined by the number “ASN”.
    The final string “^[0-9]+$” is a little more complicated match. Immediately we can see that the string starts (“^”), and we can see later that it ends (“$”). In the middle we see a range of numbers 0-9 in brackets, followed by the plus sign. The numbers in brackets mean that any number from zero to nine can be matched, or in other words, any number. Next we have the plus sign which means one or more instances. This string “[0-9]+” therefore means one or more instance of any number, or in other words any number including numbers with multiple characters (i.e. 1, 12, 123, 1234, 12345678, etc.). When we combine these all together this string means routes originated in any directly connected single AS, or in other words, the routes directly originated by the peers of your AS.
    Now let’s look at a more complicated match, and using the above character patterns we will see how we can construct the expression step by step. Suppose we have the following topology below, where we are looking at the network from the perspective of AS 100.
    +--------+ +--------+ +--------+ +--------+
    
    | AS 200 |-| AS 201 |-| AS 202 |-| AS 203 |\
    
    +--------+ +--------+ +--------+ +--------+ \
    
                                                 \
    
               +--------+ +--------+ +--------+\  \
    
               | AS 300 |-| AS 301 |-| AS 302 | \  \
    
               +--------+ +--------+ +--------+  \  -+--------+
    
                                                  >--| AS 100 |
    
                          +--------+ +--------+  /  -+--------+
    
                          | AS 400 |-| AS 401 | /  /
    
                          +--------+ +--------+/  /
    
                                                 /
    
                                     +--------+ /
    
                                     | AS 500 |/
    
                                     +--------+
    
    AS 100 peers with ASes 203, 302, 401, and 500, who each have peers as diagramed above. AS 100 wants to match routes originated from its directly connected customers (ASes 203, 302, 401, and 500) in addition to routes originated from their directly connected customers (ASes 202, 301, and 400). The easiest way to create this regular expression would be to think about what we are first trying to match, and then write out all possibilities of these matches. In our case these possibilities are:
    203
    
    203 202
    
    302
    
    302 301
    
    401
    
    401 400
    
    500
    
    Now we could simply create an expression with multiple lines (7 lines to be exact) that would match all of the possible AS paths, but suppose that AS 100 wants to keep this match as flexible as possible so that it will apply to any other ASes in the future. Now let’s try to generalize the above AS-Path information into a regex.
    First off we know that each of the matches is going to start and going to end. This means that the first character we will have is “^” and the last character is “$”. Next we know that between the “^” and “$” there will be either one AS or two ASes. We don’t necessarily know what numbers these ASes will be, so for the time being let’s use the placeholder “X”. Based on this our new possible matches are:
    ^X$
    
    ^X X$
    
    Next let’s reason out what X can represent. Since X is only one single AS, there will be no spaces, commas, parentheses, or any other special type characters. In other words, X must be a number. However, since we don’t know what the exact path is, we must take into account that X may be a number with more than one character (i.e. 10, 123, or 10101). This essentially equates to one or more instance of any number zero through nine. In regular expression syntax our two matches would therefore now read:
    ^[0-9]+$
    
    ^[0-9]+ [0-9]+$
    
    This expressions reads that we either have a number consisting of one or more characters zero through nine, or a number consisting of one or more characters zero through nine followed by a space and then another number consisting of one or more characters zero through nine. This brings our expression down to two lines as opposed to our original seven, but let’s see how we can combine the above two as well. To combine them, first let us compare what is different between them.
    ^[0-9]+$
    
    ^[0-9]+ [0-9]+$
    
    From looking at the expressions it is evident that the sequence “ [0-9]+” is the difference. In the first case “ [0-9]+” does not exist in the expression. In the second case “ [0-9]+” does exist in the expression. In other words, “ [0-9]+” is either true or false. True or false (0 or 1) is represented by the character “?” in regex syntax. Therefore we can reduce our expression to:
    ^[0-9]+ [0-9]+?$
    
    At this point we run into a problem with the order of operations of the regex. As denoted above the question mark will apply only to the plus sign, and not to the range [0-9]. Instead, we want the question mark to apply to the string “ [0-9]+” as a whole. Therefore this string needs to be grouped together using parentheses. Parentheses are used in regular expressions as simply a logical grouping. Therefore our final expression reduces to:
    ^[0-9]+( [0-9]+)?$
    
    Note that to match a question mark in IOS, the escape sequence CTRL-V or ESC-Q must be entered first, otherwise the IOS parser will interpret the question mark as an attempt to invoke the context sensitive help.

    Monday, January 27, 2020



    Halo, jumpa lagi,

    Kita akan belajar bagaimana caranya bikin smokeping latency grapher, semacem ping monitoring gitu lah, yang tujuannya biar monitor berapa sih ping dari server ke target remote dan disertakan dengan log nya, jam sekian intermittent, dlsb.

    Baiklah, pertama tama, install dahulu 

    apt install sendmail sendmail-bin mailutils
    lalu
    mkdir -m 700 /etc/mail/authinfo 
    lalu edit file gmail-smtp-auth
     /etc/mail/authinfo/gmail-smtp-auth
     kemudian isikan
    AuthInfo: "U:root" "I:USER@gmail.com" "P:GMAIL_USER_PASSWORD"
    sesuaikan dengan email gmail anda dan passwordnya

    sekarang generate sendmail gmail authentication
    makemap hash /etc/mail/authinfo/gmail-smtp-auth < /etc/mail/authinfo/gmail-smtp-auth
    jika sudah akan terbentuk file /etc/mail/authinfo/gmail-smtp-auth.db

    kemudian edit file /etc/mail/sendmail.mc

    di baris paling bawah, ubah setingan seperti berikut ini
    dnl #
    dnl # Defining Gmail Smarthost for sendmail
    define(`SMART_HOST',`[smtp.gmail.com]')dnl
    define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
    define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
    define(`confAUTH_OPTIONS', `A p')dnl
    TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
    define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
    FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-smtp-auth.db')dnl
    dnl #
    dnl # Default Mailer setup
    MAILER_DEFINITIONS
    MAILER(`local')dnl
    MAILER(`smtp')dnl
    kemudian eksekusi
    make -C /etc/mail
    ...
    Creating /etc/mail/relay-domains
    # Optional file...
    Updating Makefile ...
    Reading configuration from /etc/mail/sendmail.conf.
    Validating configuration.
    Creating /etc/mail/Makefile...
    Updating sendmail.cf ...
    The following file(s) have changed:
      /etc/mail/relay-domains /etc/mail/sendmail.cf
    ** ** You should issue `/etc/init.d/sendmail reload` ** **
    make: Leaving directory '/etc/mail'
    DONE!

    jangan lupa reload sendmailnya /etc/init.d/sendmail reload
    untuk testnya silahkan bisa lakukan seperti berikut :

    echo "This is a test for sendmail gmail relay" | sendmail test-user@gmail.com

    Monday, September 9, 2019


    Kali ini saya akan share tips menambahkan gadget ke dalam addresslist mikrotik

    :local newDynamics value=[/ip dhcp-server lease find dynamic=yes];
    :local newList value="";
    :foreach i in=[$newDynamics] do={
    :local dynamicIP [/ip dhcp-server lease get $i address];
    :local dynamicMAC [/ip dhcp-server lease get $i mac-address];
    :local dynamicHOST [/ip dhcp-server lease get $i host-name];
    :if ($dynamicHOST~"(Andro|andro|Redmi|redmi|Vivo|vivo|Iphone|iphone|Galaxy|galaxy|BLACKBER)") do={
          /ip firewall address-list add list=cidr_hs_office address=$dynamicIP comment=$dynamicHOST
          :log warning "$dynamicIP added"
          }
    }
    script diatas silahkan tambahkan pada system => scheduler

    Tuesday, August 27, 2019

    Kali ini saya akan bagi tips buat anda yang pengen bikin address-list akamai di mikrotik.
    OK, saya anggap anda bisa searching di bgp.he.net untuk mendapatkan informasi as-number akamai
    kemudian di blog ini juga sudah ada generate prefix berdasarkan asnumber, silahkan cari.
    setelah ini anggaplah sudah ter-generate dan muncul 2 file berisi list ip akamai tadi


    kemudian, gabunglah kedua file tadi
    /dump # cat  AS35994-AS35994-akamai.rsc >> AS20940-AS20940-akamai.rsc
    /dump # sort --unique -k7 AS20940-AS20940-akamai.rsc >> cidr_akamai.rsc 

    contoh hasilnya seperti berikut
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.251.0/24
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.252.0/22
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.34.0/24
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.38.0/24
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.40.0/24
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.48.0/24
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.51.0/24
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.54.0/23
    /ip firewall address-list add list=cidr_akamai comment=AS20940-akamai address=96.7.74.0/24

    jika sudah, maka siap di import di mikrotik anda.

    note::
     --unique = berarti filter ip address tanpa duplikat
    -k7 = adalah kolom ke-7 yang akan kita urutkan



    on-up
    ====

    :local remote
    :set remote $"remote-address"
    :log warning ("wellcome ppp-$user ( $remote )")
    :if ( [ /ppp secret get "$user" comment ] = "" ) do={
    :local month
    :local year
    :local yeardiv
    :local yearmult
    :local leapyear
    :local lastday
    :local date [ /system clock get date ]
    :local time [ /system clock get time ]
    # ambil nama bulan dan tahun dari date
    :set month [:pick $date 0 3]
    :set year [:pick $date 7 11]
    # check tahun kabisat atau bukan
    :set yeardiv ($year / 4)
    :set yearmult ($yeardiv * 4)
    :if ([$yearmult] = $year) do={ :set leapyear true } else={ :set leapyear false }
    # set nilai lastday sesuai nama bulan dan tahun
    :if ([$month] = "jan") do={ :set lastday 31d }
    :if ([$month] = "feb") do={
    :if ($leapyear = true) do={ :set lastday 29d }
    :if ($leapyear = false) do={ :set lastday 28d }
    }
    :if ([$month] = "mar") do={ :set lastday 31d }
    :if ([$month] = "apr") do={ :set lastday 30d }
    :if ([$month] = "may") do={ :set lastday 31d }
    :if ([$month] = "jun") do={ :set lastday 30d }
    :if ([$month] = "jul") do={ :set lastday 31d }
    :if ([$month] = "aug") do={ :set lastday 31d }
    :if ([$month] = "sep") do={ :set lastday 30d }
    :if ([$month] = "oct") do={ :set lastday 31d }
    :if ([$month] = "nov") do={ :set lastday 30d }
    :if ([$month] = "dec") do={ :set lastday 31d }
    # cek nilai lastday
    #:log info ("$lastday")
    /ppp secret set $user comment="$date $time"
    /system scheduler remove [find name="ppp-$user"]
    /system scheduler add interval=$lastday name="ppp-$user" on-event="/ppp active remove [find user=\"$user\"]\r\n/ppp secret disable [find name=\"$user\"]\r\n/system scheduler remove [find name=\"ppp-$user\"]" start-date=$date start-time=$time
    } else={
    :local zoky [ /ppp secret get "$user" comment ]
    :local zoky1 " $zoky"
    :local zoky2
    :for i from=0 to=([:len $zoky1] - 1) do={
    :local char [:pick $zoky1 $i]
    :if ($char = " ") do={
    :set $char "\\ "
    }
    :set zoky2 ($zoky2 . $char)
    }
    :local var $zoky2
    :local myArray [:toarray [:pick $var ([:find $var " "]+1) [:len $var]]]
    :local month
    :local year
    :local yeardiv
    :local yearmult
    :local leapyear
    :local lastday
    :local comdate [:pick $myArray 0]
    :local comtime [:pick $myArray 1]
    # ambil nama bulan dan tahun dari comdate
    :set month [:pick $comdate 0 3]
    :set year [:pick $comdate 7 11]
    # check tahun kabisat atau bukan
    :set yeardiv ($year / 4)
    :set yearmult ($yeardiv * 4)
    :if ([$yearmult] = $year) do={ :set leapyear true } else={ :set leapyear false }
    # set nilai lastday sesuai nama bulan dan tahun
    :if ([$month] = "jan") do={ :set lastday 31d }
    :if ([$month] = "feb") do={
    :if ($leapyear = true) do={ :set lastday 29d }
    :if ($leapyear = false) do={ :set lastday 28d }
    }
    :if ([$month] = "mar") do={ :set lastday 31d }
    :if ([$month] = "apr") do={ :set lastday 30d }
    :if ([$month] = "may") do={ :set lastday 31d }
    :if ([$month] = "jun") do={ :set lastday 30d }
    :if ([$month] = "jul") do={ :set lastday 31d }
    :if ([$month] = "aug") do={ :set lastday 31d }
    :if ([$month] = "sep") do={ :set lastday 30d }
    :if ([$month] = "oct") do={ :set lastday 31d }
    :if ([$month] = "nov") do={ :set lastday 30d }
    :if ([$month] = "dec") do={ :set lastday 31d }
    # cek nilai lastday
    #:log info ("$lastday")
    /system scheduler remove [find name="ppp-$user"]
    /system scheduler add interval=$lastday name="ppp-$user" on-event="/ppp active remove [find user=\"$user\"]\r\n/ppp secret disable [find name=\"$user\"]\r\n/system scheduler remove [find name=\"ppp-$user\"]" start-date=$comdate start-time=$comtime
    } :local profile [/ppp secret get [find name="$user"] profile]
    :local rateLimit [/ppp profile get [find name="$profile"] rate-limit]
    :local parent [/ppp profile get [find name="$profile"] parent]
    :local queue [/ppp profile get [find name="$profile"] queue]
    /queue simple remove [find name="$user-$remote"]
    /queue simple add max-limit="$rateLimit" name="$user-$remote" parent="$parent" queue="$queue/$queue" target="$remote"
    /queue simple remove [find where name~"-$user"]


    on-down
    ======
    :local remote
    :set remote $"remote-address"
    :log warning ("goodbye $user ( $remote )")
    :local bytes [/queue simple get [find name="$user-$remote"] bytes]
    :local totalbytes
    :local arraybytes [:toarray [:pick $bytes ([:find $bytes "/"]+1) [:len $bytes]]]
    :local upbytes [:pick $arraybytes 0]
    :local downbytes [:pick $arraybytes 1]
    :set totalbytes ($upbytes+$downbytes)
    :local zoky [/ppp secret get "$user" comment]
    :local zoky1 " $zoky"
    :local zoky2
    :for i from=0 to=([:len $zoky1] - 1) do={
    :local char [:pick $zoky1 $i]
    :if ($char = " ") do={
    :set $char "\\ "
    }
    :set zoky2 ($zoky2 . $char)
    }
    :local commentppp $zoky2
    :local arraycomment [:toarray [:pick $commentppp ([:find $commentppp " "]+1) [:len $commentppp]]]
    :local comdate [:pick $arraycomment 0]
    :local comtime [:pick $arraycomment 1]
    :local combytes [:pick $arraycomment 2]
    :if ($combytes = "") do={
    /ppp secret set "$user" comment="$comdate $comtime $totalbytes"
    } else={
    :local alltotalbytes
    :set alltotalbytes ($combytes+$totalbytes)
    /ppp secret set "$user" comment="$comdate $comtime $alltotalbytes"
    }
    /queue simple remove [find name="$user-$remote"]
    note
    ===
    profile harap di set max-limit, parent dan queue-typenya
    bikin scheduler di run perjam atau terserah anda intervalnya
    untuk update counter usagenya
    :local userppp
    :local usersimple
    :foreach i in=[/ppp secret find] do {
    :set userppp ( userppp [/ppp secret get $i name])
    :local zoky [/ppp secret get "$userppp" comment]
    :local zoky1 " $zoky"
    :local zoky2
    :for i from=0 to=([:len $zoky1] - 1) do={
    :local char [:pick $zoky1 $i]
    :if ($char = " ") do={
    :set $char "\\ "
    }
    :set zoky2 ($zoky2 . $char)
    }
    :local commentppp $zoky2
    :local arraycomment [:toarray [:pick $commentppp ([:find $commentppp " "]+1) [:len $commentppp]]]
    :local comdate [:pick $arraycomment 0]
    :local comtime [:pick $arraycomment 1]
    :local combytes [:pick $arraycomment 2]
    :if ([/ppp secret get [/ppp secret find name="$userppp"] profile] != "") do {
    :foreach j in=[/queue simple find where name~"$userppp"] do {
    :set usersimple ( usersimple [/queue simple get $j name])
    :local bytes [/queue simple get [/queue simple find name="$usersimple"] bytes]
    :local totalbytes
    :local arraybytes [:toarray [:pick $bytes ([:find $bytes "/"]+1) [:len $bytes]]]
    :local upbytes [:pick $arraybytes 0]
    :local downbytes [:pick $arraybytes 1]
    :set totalbytes ($upbytes+$downbytes)
    :if ($combytes < 0) do {
    :local alltotalbytes
    :if (($comtime < 0)&&($combytes < 0)) do {
    :set alltotalbytes ($comdate+$totalbytes)
    /ppp secret set "$userppp" comment="$alltotalbytes"
    } else {
    :set alltotalbytes ($combytes+$totalbytes)
    /ppp secret set "$userppp" comment="$comdate $comtime $alltotalbytes"
    }
    #:log warning "$userppp $comdate $comtime $combytes $usersimple $totalbytes $alltotalbytes"
    } else {
    :if ($totalbytes = $totalbytes) do {
    #:log warning "no update usage ppp"
    } else {
    :local alltotalbytes
    :if (($comtime < 0)&&($combytes < 0)) do {
    :set alltotalbytes ($comdate+$totalbytes)
    /ppp secret set "$userppp" comment="$alltotalbytes"
    } else {
    :set alltotalbytes ($combytes+$totalbytes)
    /ppp secret set "$userppp" comment="$comdate $comtime $alltotalbytes"
    }
    #:log warning "$userppp $comdate $comtime $combytes $usersimple $totalbytes $alltotalbytes"
    }
    }
    }
    }
    }

    credits : zoky raharjo (fb) 

    Wednesday, May 22, 2019

    Yup, dah tau maksudnya kan ? kali ini saya akan share tips gimana caranya jalanin monitor trafik pada interface tertentu (ether1 misalnya) pada pelanggan, yang nantinya dapat digunakan sebagai report ke pelanggan bahwa penggunaan dalam satu bulan ini sudah mencapai sekian GigaByte. Begitu lah kira kira. nah berikut scriptnya, silahkan dibikin scheduler

    :global iface ether1
    :global trafikawal
    :global trafik
    # reset tanggal 1
    #/system ntp client set primary-ntp=[:resolve id.pool.ntp.org] enabled=yes
    #/system clock set time-zone-name="Asia/Jakarta"
    :local date [/system clock get date]
    :local tanggal [ :pick $date 4 6 ]
    #:log warning $tanggal
    :if ($tanggal = 1) do={:set trafikawal 0}
    :set trafikawal [/interface get [find name=$iface] tx-byte]
       :if ($trafikawal > 1073741824) do={
       :set trafik ($trafikawal / 1073741824)
       :set trafik ($trafik." GB")
       } else={
       :set trafik ($trafikawal / 1048576)
       :set trafik ($trafik." MB")
       }
    :log warning "trafik $iface = $trafik"
    /in ethernet set $iface comment="$trafikawal"

    Nah, setelah diteliti lagi, ternyata script diatas masih ada kekurangan, yaitu ketika perangkat reboot, kereset jadi 0, akhirnya gw ubah jadi revisi scriptnya begini

    :global iface ether1
    :global trafikFresh
    :global trafikSave
    :global trafikBit
    :global trafikBytes
    :global trafikTotal
    :local date [/system clock get date]
    :local tanggal [ :pick $date 4 6 ]
    #:log warning $tanggal
    :if ($tanggal = 1) do={:set trafikBit 0}
    # jika direboot ambil dari comment interface
    :if ([:len $trafikFresh ] = 0) do={
    :set trafikSave [/interface get [find name=$iface] comment]
    # catat ke variable
    :set trafikFresh [/interface get [find name=$iface] tx-byte]
    :set trafikTotal ([:tonum $trafikSave] + [:tonum $trafikFresh])
    :set trafikBit $trafikTotal
    } else={
    :set trafikBit  [/interface get [find name=$iface] tx-byte]
    :set trafikTotal ([:tonum $trafikSave] + [:tonum $trafikBit])
    }
    # jika ukuran gigabyte
    :if ($trafikTotal > 1073741824) do={
    :set trafikBytes ($trafikTotal / 1073741824)
    :set trafikBytes ($trafikBytes." GB")
    } else={
    :set trafikBytes ($trafikTotal / 1048576)
    :set trafikBytes ($trafikBytes." MB")
    }
    :log warning "trafik $iface = $trafikBytes"
    /in ethernet set $iface comment="$trafikTotal"

    nanti hasilnya seperti berikut :

    Saturday, May 18, 2019


    Hmm.. kali ini mimin bakal share tips & trik cara gimana saat link intermittent maka dilakukan tindakan, di sini mimin disable peer yg ngarah ke sono. Bisa sobat kembangkan sendiri yah. Ok langsung aja bikin scheduler
    :global intermit
    :global melar
    :global limitnotif
    :local avgRtt;
    :local pin
    :local pout
    :local target 124.195.38.1
    /tool flood-ping $target count=10 do={
      :if ($sent = 10) do={
        :set avgRtt $"avg-rtt"
        :set pout $sent
        :set pin $received
      }
    }
    :local ploss (100 - (($pin * 100) / $pout))
    :local LogErrorMsg ("Ping average for host%0A$target = ".[:tostr $avgRtt]."ms%0Apacket loss = ".[:tostr $ploss]."%")
    :local LogWarnMsg ("Ping average for host%0A$target = ".[:tostr $avgRtt]."ms%0Apacket loss = ".[:tostr $ploss]."%")
    :local LogError ("Ping average for $target = ".[:tostr $avgRtt]."ms - packet loss: ".[:tostr $ploss]."%")
    :local LogWarn ("Ping average for $target = ".[:tostr $avgRtt]."ms - packet loss: ".[:tostr $ploss]."%")
    :if ($avgRtt > 20) do={
    :set melar ($melar +1)
    :log error "$LogError"
    } else={
    :log warning "$LogWarn"
    :set melar 0
    }
    # jika packetloss diatas 10% maka
    :if ([:tostr $ploss] > 10) do={
       :set intermit ($intermit +1)
       :set limitnotif ($limitnotif +1)
       } else={
       :set intermit 0
       }
    # jika intermitent terus
    :if ($intermit >=10) do={
       :local pesan "$LogErrorMsg"
       /routing bgp peer set [find name~"INIX" disabled=no] disabled=yes
       /ip firewall mangle set [find comment="backup_conn" disabled=yes] disabled=no
       :if ($limitnotif = 2) do={
          /tool fetch url="https://api.telegram.org/bot380921546:AAGn69QpFDuLSOQd3E3JtI5nhfKDkdKMW/sendMessage?chat_id=-20353xxx&text=$pesan" keep-result=no
         }
       }
    # jika tidak intermitent
    :if ($intermit = 0) do={
       :if ($limitnotif >=10)  do={
       :set limitnotif 0
       }
       :if ($limitnotif =0) do={
       :set limitnotif ($limitnotif +1)
       }
       /routing bgp peer set [find name~"INIX" disabled=yes] disabled=no
       /ip firewall mangle set [find comment="backup_conn" disabled=no] disabled=yes
       :local pesan "$LogWarnMsg"
       :if ($limitnotif =2) do={
          /tool fetch url="https://api.telegram.org/bot380921546:AAGn69QpFDuLSOQd3E3JtI5nhfKDkdKMW/sendMessage?chat_id=-20353xxx&text=$pesan" keep-result=no
          }
       }

    Tuesday, April 30, 2019


    Pernah nggak kalian membuat VPN server, entah itu PPTP, EOIP, L2TP, dan lain sebagainya ??
    Permasalahan yang mimin hadapi ketika membuat VPN server pada MikroTik, ketika koneksi yg ditumpangi (baca:InetBroadband) kadang suka ngetrip, terkadang session L2TP menjadi diskonek yg mengakibatkan laju jalur L2TP terhambat, Solusinya di redial, atau pada ppp active dilakukan remove secara manual.

    Hal ini sangat merepotkan kl harus manual, soalnya mimin sering otw ga sempet monitor ngawasin 24jam! Nah solusi berikut ini sangat recomended bagi anda yang bekerja sebagai VPNers (yaelah). Langsung aja deh, buat scheduler di mikrotik kalian isinya begini.

    :global count [/ppp active print count-only]
    :local i
    :for i from=1 to=$count do={
       :global user
       :global vpnip
       :set user [/ppp active get $i name];
       :delay 1
       :set vpnip [/ppp active get $i address];
       :delay 1
       :if ([/ping $vpnip count=2] = 0) do={
          /ppp active remove numbers=$i
          :log error "$user $vpnip request time out!"
          } else={
          :log warning "$user $vpnip is reply..."
          }
       }
     }

    Saturday, April 27, 2019



    Kali ini saya akan bagi tips buat monitoring Rate pada Ethernet Mikrotik lalu dilaporkan ke Telegram. OK langsung aja ya, buat scheduler isinya seperti berikut

    :global perulangan
    :global statusEth
    :global iface "ether2-CDIX"
    /int eth monitor ether2 once do={
       :if ($"rate" = "100Mbps" && $perulangan <3) do={
          :set statusEth 0
          :set perulangan ($perulangan +1)
          :log error "$iface is 100Mbps"
          :local pesan "$iface is 100Mbps";
          /tool fetch url="https://api.telegram.org/bot380921xxx:AAGn69QpFDuLSOQd3E3JtIJxxxxx/sendMessage?chat_id=-20353xxx&text=$pesan" keep-result=no
          :if ($perulangan = 3 && $statusEth = 0) do={
             :log error "$iface MASIH 100Mbps"
             :local pesan "$iface MASIH 100Mbps"
             /tool fetch url="https://api.telegram.org/bot380921xxx:AAGn69QpFDuLSOQd3E3JtIJxxxxx/sendMessage?chat_id=-20353xxx&text=$pesan" keep-result=no
             }
          } else={
             :set statusEth 1
             :if ($statusEth = 1 && $perulangan >= 1000) do={:set perulangan 1}
             :if ($statusEth = 1 && $perulangan >= 1) do={:set perulangan ($perulangan +1)}
             :if ($perulangan = 2) do={
                :log warning "$iface 1Gbps"
                :local pesan "Alhamdulillaah $iface 1Gbps";
                /tool fetch url="https://api.telegram.org/bot380921xxx:AAGn69QpFDuLSOQd3E3JtIJxxxxx/sendMessage?chat_id=-20353xxx&text=$pesan" keep-result=no
                }
          }
    }

    Friday, November 16, 2018

    sebagai catatan untuk menangkap gadget yang berada di dhcp-server leases mikrotik kemudian ditambahkan ke addresslist. terserah mau di mark routing atau bagaimana yg jelas sudah masuk di addresslist

    :local newDynamics value=[/ip dhcp-server lease find dynamic=yes];
    :local newList value="";
    :foreach i in=[$newDynamics] do={
    :local dynamicIP [/ip dhcp-server lease get $i address];
    :local dynamicMAC [/ip dhcp-server lease get $i mac-address];
    :local dynamicHOST [/ip dhcp-server lease get $i host-name];
    :if ($dynamicHOST~"(Andro|andro|Redmi|redmi|Vivo|vivo|Iphone|iphone|Galaxy|galaxy|BLACKBER)") do={
          /ip firewall address-list add list=cidr_hs_office address=$dynamicIP comment=$dynamicHOST
          :log warning "$dynamicIP added"
          }
    }

    Sunday, August 26, 2018


    Yeah, kali ini saya akan share script untuk me-generate netwatch. Hanya untuk catatan pribadi aja sih

    langsung saja

    :for x from=2 to=254 step=8 do={/tool netwatch add host="10.10.40.$x" interval=00:00:03 down-script=":local client [/tool netwatch get [/tool netwatch find host=\"10.10.40.$x\"] comment ];\n\n :log error \"\$client down\";\n\n /system script run telolet" up-script=":local client [/tool netwatch get [/tool netwatch find host=\"10.10.40.$x\"] comment ];\n\n :log warning \"\$client up\";\n\n /system script run up"}

    Saturday, June 2, 2018


    :foreach i in=[/ip firewall address-list find list=350 ] do={
    :local addrlist350 [/ip firewall address-list get $i address ]
    :log warning $addrlist350
    /ip fire mangle add chain=postrouting dst-address=$addrlist350 connection-mark=ggc_conn action=mark-packet new-packet-mark="ggc_$user" comment=$user

    Friday, June 1, 2018


    tambahkan script di scheduler dengan run startup
    :if ([:len ($000 || $150 || $200 || $250 || $300 || $350)] = 0) do={
    :global 000 10.8.8.0/27
    :global 150 10.8.8.32/27
    :global 200 10.8.8.64/26
    :global 250 10.8.8.128/26
    :global 300 10.8.8.192/27
    :global 350 10.8.8.224/27
    }

    kemudian bikin pool-ip
    /ip pool
    add name=000 ranges=10.8.8.2-10.8.8.30
    add name=150 ranges=10.8.8.33-10.8.8.62
    add name=200 ranges=10.8.8.65-10.8.8.126
    add name=250 ranges=10.8.8.129-10.8.8.191
    add name=300 ranges=10.8.8.193-10.8.8.222
    add name=350 ranges=10.8.8.225-10.8.8.254

    tambahkan di profile-pppoe on login
    :local parent PPPOE
    :local ippppoe [/ip address get [/ip address find interface=$user] network]
    :local ipclient
    :local iprouter [/ip address get [find  comment=$user] address ]
    :for i from=( [:len $iprouter] - 1) to=0 do={
    :if ( [:pick $iprouter $i] = "/") do={
    :set $ipclient ([:pick $iprouter 0 $i] +1)
    }
    }

    :if ($ippppoe in $suspend) do={
       :if ([:len [/ip firewall address-list find list=cidr_suspend comment=$user]] = 0 ) do={
       /ip firewall address-list add address=$ipclient list=cidr_suspend comment=$user
       }
    /queue simple add target=$ipclient name=$user parent=$parent max-limit=5000000/5000000
    }
    :if ($ippppoe in $150) do={
    /queue simple add target=$ipclient name=$user parent=$parent max-limit=2000000/2000000
    /ip firewall address-list remove [find list=cidr_suspend comment=$user]
    }
    :if ($ippppoe in $200) do={
    /queue simple add target=$ipclient name=$user parent=$parent max-limit=2500000/2500000
    /ip firewall address-list remove [find list=cidr_suspend comment=$user]}
    :if ($ippppoe in $300) do={
    /queue simple add target=$ipclient name=$user parent=$parent max-limit=3000000/3000000
    /ip fire mangle add chain=postrouting dst-address=$ipclient connection-mark=ggc_conn action=mark-packet new-packet-mark="ggc_$user" comment=$user
    /queue tree add name=$user limit-at=2000000 max-limit=5000000 parent=DN-PPPOE packet-mark="ggc_$user"
    /ip firewall address-list remove [find list=cidr_suspend comment=$user]
    }
    :if ($ippppoe in $350) do={
    /queue simple add target=$ipclient name=$user parent=$parent max-limit=3000000/3500000
    /ip fire mangle add chain=postrouting dst-address=$ipclient connection-mark=ggc_conn action=mark-packet new-packet-mark="ggc_$user" comment=$user
    /queue tree add name=$user limit-at=2000000 max-limit=8000000 parent=DN-PPPOE packet-mark="ggc_$user"
    /ip firewall address-list remove [find list=cidr_suspend comment=$user]
    }


    tambahkan di profile-pppoe on logout
    :log error "$user logout $ipclient"
    /queue simple remove [find name=$user]
    /queue tree remove [find name=$user]
    /ip fire mangle remove [find comment=$user]



    Kali ini saya akan berikan tips anti mainstream, dimana deliver ke pelanggan menggunakan ip static, namun secara management user dicontrol oleh userman. Teknik ini dibuat karena problem yang penulis alami ketika deliver bandwidth ke pelanggan mengalami kendala link dan perangkat yang dipasang pppoe-client tidak sempurna jika menggunakan produk selain mikrotik (tplink, tenda, maupun ubnt).
    Problem menggunakan TPLINK = dialup lama
    Problem menggunakan TENDA = dialup cenderung lebih cepat daripada TPLINK namun tetap saja ada jeda waktu yang membuat risih pelanggan, karena established pppoe butuh waktu yang cukup lama.
    Problem menggunakan UBNT = sama persis seperti TENDA maupun TPLINK.

    Nah, dari problem diatas, kita siasati seperti berikut :

    1. Sediakan Router utama, yang berisi userman berikut limiternya
    2. Sediakan Router khusus untuk dial pppoe-client
    3. Buat Point to point ip static antara ROUTER2 ke masing masing client, usahakan namanya sama dengan pppoe-client.
    4. Bikin semua point to point via pppoe dengan menggunakan kedua router tersebut
    5. Untuk Router point nomor 2, nantinya digunakan untuk dial semua user. Kemudian bikin environment gimana caranya agar ip p2p static dibikin mark-routing ke pppoe-client tadi.
    6. Dengan begitu, untuk 1 user memerlukan 1 mangle dan 1 mark routing, dan ini nanti kita buat secara otomatis berdasarkan user yang berhasil dial dengan status R pada interface pppoe-client.
    7. Trafik pppoe-client dan limiter pppoe-client tetap dibaca oleh Router point 1.
    8. Done !
    Ok langsung saja, script pada profile default ppp, pada on logon kasih script berikut :

    :local iface [/interface pppoe-client get [find running=yes] name]
    :local ipaddress ([/ip address get [find  comment=$iface] address ])
    :for i from=( [:len $ipaddress] - 1) to=0 step=-1 do={
          :if ( [:pick $ipaddress $i] = "/") do={
             :set ipaddress ( [:pick $ipaddress 0 $i] +1)
             }
          }
    :log warning $ipaddress
    /ip firewall mangle add comment=$iface chain=prerouting src-address=$ipaddress action=mark-routing new-routing-mark=$iface passthrough=no
    /ip route add routing-mark=$iface gateway=$iface

    Lalu untuk on logout script :
    :local iface [/interface pppoe-client get [find running=no] name]
    :log error "$iface removed"
    /ip fire mangle remove [find comment=$iface]
    /ip route remove [find routing-mark=$iface]

    Semoga bermanfaat.

    Monday, May 21, 2018


    Pernah mengalami seperti ini :

    Yubs, tentu sangat membosankan bukan? kenapa terjadi seperti itu ? jawabannya adalah karena si mbah google mendeteksi adanya malware atau sejenis spam yang melakukan query tertentu pada mesin pencarian google sehingga perlu adanya pembatasan atau pencegahan query. Bisa dibayangkan jika aktivitas spamming ini tidak diatasi pihak google. Tentu hal ini sudah dipikirkan mbah google agar kejadian ini teratasi dengan cara memberikan captcha. Perlu diketahui, ada beberapa kasus dimana tidak semua komputer terkena spam, mengenai hal ini saya kurang paham methode apa yg dipakai google untuk menerapkan pencegahan, karena fakta di lapangan ketika 1 ip public indih*me dishare ke banyak user, tidak semua kena spam. Namun jika terus menerus kena spam, dalam kurun waktu sekitar 30 menit maka semua komputer muncul captcha. Solusi satu-satunyanya saat ini harus generate ip baru. Nah lalu bagaimana cara mendeteksi kena spam ? tentu kita memanfaatkan domain ipv4.google.com/sorry/ bla bla bla yang akan kita tangkap dan kita eksekusi perintah untuk redial pppoe indih*me.

    Baiklah langsung saja, kali ini saya akan bagi tips versi kedua yang mana pada script ini ada pembaharuan sehingga lebih valid. Karena terkadang akses ke google kena spam hanya ke beberapa pc saja dan pc lainnya tidak kena. solusinya gunakan layer7.
    Pertama tama, buat regex layer7 pada mikrotik kasih nama spamgoogle :
    ^.*(ipv4.google.com)

    kemudian buat rule firewall filter agar address yg kena spam masuk ke address-list. (sesuaikan cidr_nat adalah pool ip client anda)
    /ip fi fi add action=add-src-to-address-list address-list=kena_spam address-list-timeout=\
    none-dynamic chain=forward comment=kena_spam layer7-protocol=spamgoogle protocol=tcp src-address-list=cidr_nat
    kemudian buat script seperti berikut dan jangan lupa buat schedulernya.
    :global iface 0pppoe0
    :global currentIP
    #:if ([:len [/ip firewall address-list find list=kena_spam dynamic=yes ]] != 0 ) do={
    :if ([/ip firewall address-list print  count-only where list=kena_spam] >=5) do={
    :log error "akses google kena spam"
    /in pppoe-client disable $iface
    :delay 2
    /in pppoe-client enable $iface
    :delay 2
    :set $currentIP ([/ip address get [find interface="$iface"] address])
    :for i from=( [:len $currentIP] - 1) to=0 step=-1 do={
          :if ( [:pick $currentIP $i] = "/") do={
             :set currentIP [:pick $currentIP 0 $i]
             }
          }
    :foreach i in=[/ip firewall address-list find list=kena_spam ] do={:put $i; /ip firewall address-list remove $i }
    :log warning "telah digenerate dengan ip baru : $currentIP"
    :local router [/system identity get name]
    :local time [/system clock get time]
    :local date [/system clock get date]
    :local voltage [/system health get voltage]
    :local tegangan (. [:pick $voltage 0 2] . "," . [:pick $voltage 2 3] ." volt")
    :local pesan ("[ $router ]%0A" ."GENERATE IP%0A$currentIP:81/userman%0A103.77.159.87:81/userman%0AKENA SPAM pada : %0A" . $time .", ".$date. "%0AVoltase saat ini $tegangan.")
    /tool fetch url="https://api.telegram.org/bot38xx21546:AAGn69QpFDuLSOQd3E3JtI5nhfUmg05hQys/sendMessage?chat_id=-20xx3762&text=$pesan" keep-result=no
    }
    :if ($currentIP  in 10.0.0.0/8) do={
    :log error "dapet ip private! redial kembali untuk mendapatkan ip kepala 36";
    /in pppoe-client disable $iface
    :delay 2
    /in pppoe-client enable $iface
    :delay 2
    :set $currentIP ([/ip address get [find interface="$iface"] address])
    :for i from=( [:len $currentIP] - 1) to=0 step=-1 do={
          :if ( [:pick $currentIP $i] = "/") do={
             :set currentIP [:pick $currentIP 0 $i]
             }
          }
    :foreach i in=[/ip firewall address-list find list=kena_spam ] do={:put $i; /ip firewall address-list remove $i }
    :log warning "telah digenerate dengan ip baru : $currentIP"
    :local router [/system identity get name]
    :local time [/system clock get time]
    :local date [/system clock get date]
    :local voltage [/system health get voltage]
    :local tegangan (. [:pick $voltage 0 2] . "," . [:pick $voltage 2 3] ." volt")
    :local pesan ("[ $router ]%0A" ."GENERATE IP%0A$currentIP:81/userman%0A103.77.159.87:81/userman%0AKENA SPAM pada : %0A" . $time .", ".$date. "%0AVoltase saat ini $tegangan.")
    /tool fetch url="https://api.telegram.org/bot38xx921546:AAGn69QpFDuLSOQd3E3JtI5nhfUmg05hQys/sendMessage?chat_id=-20353xx762&text=$pesan" keep-result=no
    }

    hasilnya :


    dan telah dilaporkan ke telegram Anda. semoga bermanfaat