GithubHelp home page GithubHelp logo

Comments (3)

happyhater avatar happyhater commented on May 24, 2024

or--

// ZmEu (whitehat.ro) 03022021
//  - RTT getter program for RTT-based actions (ARouteServer)
//
// $ gcc -o rtt_getter rtt_getter.c && ./rtt_getter 185.1.176.1
// 0.481
//
// I am not responsible for any damage.
// For educational purposes only, use at your own responsibility.
//
// Don't hate me, hate the code!#

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>

int cmd(char *ip) {
        char buf[124];
        char *ping;

        if (inet_pton(AF_INET, ip, buf)) {
                ping = "ping";
        } else if (inet_pton(AF_INET6, ip, buf)) {
                ping = "ping6";
        } else {
                ping = '\0';
        }

        if (ip == NULL || ping == NULL) {
                printf("None\n");
                return 0;
        }

        int result;
        FILE *isalive;
        memset(buf, 0, 124);
        sprintf(buf, "%s -c 1 -n -q -w 1 %s | grep 'packets'", ping, ip);
        isalive = popen(buf, "r");
        while (fgets(buf, sizeof(buf), isalive)) {
                if (!strstr(buf, "0 packets")) {
                        // interval lower than =< 1 needs super user access
                        snprintf(buf, sizeof(buf), "%s -c 3 -i 1 -n -q -w 1 %s | grep min/avg/max | egrep -o ' [0-9./]+ ms' | cut -d '/' -f 2", ping, ip);
                        system(buf);
                } else {
                        printf("None\n");
                }
                return 0;
        }
        pclose(isalive);

        return 0;
}

int main (int argc, char **argv) {
        int error;

        if (argc < 2) {
                fprintf(stderr, "[-] Syntax:\n<%s %%i>\t\t- peer IP address\n", argv[0]);
                return 1;
        }

        if (error = cmd(argv[1])) {
                fprintf(stderr, "[-] exec() returned an error: %s\n", strerror(errno));
        }

        return error;
}
ARouteServer 2021-03-02 18:39:57,678 INFO Enricher 'RTTGetter' started
ARouteServer 2021-03-02 18:40:07,787 INFO Enricher 'RTTGetter', 4 tasks left
ARouteServer 2021-03-02 18:40:10,013 INFO Enricher 'RTTGetter' completed successfully after 13 seconds
$ grep -i rtt /etc/bgpd.conf
        # RTT: 2.483 ms (normalized value: 2)
        # RTT: 1.209 ms (normalized value: 1)
        # RTT: 41.403 ms (normalized value: 41)
        # RTT: 40.268 ms (normalized value: 40)
        # RTT: 42.503 ms (normalized value: 43)
        # RTT: 43.711 ms (normalized value: 44)
# do_not_announce_to_peers_with_rtt_lower_than 5 ms
# do_not_announce_to_peers_with_rtt_lower_than 10 ms
# do_not_announce_to_peers_with_rtt_lower_than 15 ms
# do_not_announce_to_peers_with_rtt_lower_than 20 ms
# do_not_announce_to_peers_with_rtt_lower_than 30 ms
# do_not_announce_to_peers_with_rtt_lower_than 50 ms
# do_not_announce_to_peers_with_rtt_lower_than 100 ms
# do_not_announce_to_peers_with_rtt_lower_than 200 ms
# do_not_announce_to_peers_with_rtt_lower_than 500 ms

from arouteserver.

pierky avatar pierky commented on May 24, 2024

Hi @happyhater, that's great, thanks for your contribution.
Would you like to open a PR and propose the addition of the two files? They could go inside the config.d directory, where the bash version already exists.
You may add both the ksh script and the C program. I could make the changes to the doc where the usage of rtt-getter is explained and get everything merged in the next release. WDYT?

from arouteserver.

happyhater avatar happyhater commented on May 24, 2024

Hi @pierky , sure!
I guess it's better to use just C program, don't you think ?
There is it: #67

from arouteserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.