Raw Source
pacardo.james27gmail.com / Tr0janz08 IP Hunter

// ==UserScript==
// @name         Tr0janz08 IP Hunter
// @namespace    http://www.symbianize.com/showthread.php?t=1397083
// @version      1.0
// @description  This userscript automatically reconnects the dashboard until a working ip is detected.
// @author       tr0janz08 (Symbianize)
// @match        http://192.168.8.1/html/home.html
// @updateURL https://openuserjs.org/meta/mOngsAng.gA/Tr0janz08_IP_Hunter.meta.js
// ==/UserScript==

(function() {
    'use strict';
    /*
     * THIS WORK IS COPYRIGHT PROTECTED
     * http://www.copyrighted.com/copyrights/view/v6tm-qzys-ym79-9saw
     *
     * IF YOU HAVE ANY SUGGESTIONS TO IMPROVE THIS TOOL,
     * YOU CAN PM ME ON SYMBIANIZE OR ON FACEBOOK.
     */

    var username = localStorage.iphUsername || "admin";
    var password = localStorage.iphPassword || "";
    var working_ip = localStorage.iphPatterns || "10.;100.11;100.12;100.13;100.14;100.15;100.16;100.17;100.18;100.19;100.2";

    $('<input type="hidden" id="username" />').val(username).appendTo('body');
    $('<input type="hidden" id="password" />').val(password).appendTo('body');

    $('<div class="wlan_status" />')
        .html('<h2>IP Hunter <small>Modified by: KingJames</small></h2>')
        .append(
            $('<table id="ip_hunter" width="91%" />')
                .append('<tr><td colspan="2" id="err"></td></tr>')
                .append('<tr><td>Username:</td><td><input type="text" id="iph_username" style="width:92%;" /></td></tr>')
                .append('<tr><td>Password:</td><td><input type="password" id="iph_password" style="width:92%;" /></td></tr>')
                .append('<tr><td>IP Patterns:</td><td><input type="text" id="iph_patterns" style="width:92%;" /></td></tr>')
                .append('<tr><td colspan="2"><textarea style="width:95%;height:110px;" id="ip_hunter_log" readonly></textarea></td></tr>')
                .append($('<tr />').html($('<td colspan="2" style="padding: 3px 0;" />')
                    .append($('<button style="margin-right: 3px; padding: 3px 10px;" />').text('Save Changes').click(function(){
                        localStorage.iphUsername = $('#iph_username').val();
                        localStorage.iphPassword = $('#iph_password').val();
                        localStorage.iphPatterns = $('#iph_patterns').val();
                        l('Changes has been saved.');
                        $('#password').val($('#iph_password').val());
                        login(g_destnation, function() {
                            console.clear();
                            l('Successfully logged in to dashboard!');
                            s();
                        });
                        setTimeout(function() {
                            if($('.error_message').text().length > 1) {
                                l($('.error_message').text());
                                $('.error_message').hide();
                            }
                        }, 300);
                    }))
                    .append($('<button style="margin-right: 3px; padding: 3px 10px;" />').text('Login').click(function(){
                        $('#password').val($('#iph_password').val());
                        login(g_destnation, function() {
                            console.clear();
                            l('Successfully logged in to dashboard!');
                            s();
                        });
                        setTimeout(function() {
                            if($('.error_message').text().length > 1) {
                                l($('.error_message').text());
                                $('.error_message').hide();
                            }
                        }, 300);
                    }))
                    .append($('<button style="margin-right: 3px; padding: 3px 10px;" />').text('Reconnect').click(function(){
                        l('Reconnecting...');
                        r();
                    }))
                ))
        )
        .appendTo('.login_info')
    ;

    $('#iph_username').val(username);
    $('#iph_password').val(password);
    $('#iph_patterns').val(working_ip);

    function l(msg) {
        console.log(msg);
        setTimeout(function() {
            var iphLog = $('#ip_hunter_log')[0];
            iphLog.value += "\n" +msg;
            iphLog.scrollTop = iphLog.scrollHeight;
        }, 200);
    }

    function s() {
        l('Scanning...');

        getAjaxData('api/monitoring/status', function($xml) {
            var ret = xml2object($xml);

            if (ret.type == 'response') {
                var current_ip = ret.response.WanIPAddress;
                var supported = false;

                if(current_ip && current_ip !== "") {
                    console.info('Current IP: ', current_ip);
                    l('Current IP: ' + current_ip);

                    working_ip.split(";").forEach(function(ip, index) {
                        if(current_ip.split(ip).length > 1) {
                            supported = true;
                            l('Matched with pattern: '+ ip);
                        }
                        if((index + 1) === working_ip.split(";").length) {
                            if(!supported) {
                                l('Reconnecting...');
                                r();
                            } else {
                                l('IP ('+current_ip+') is valid.');
                                l('developed by: KingJames');
                                l('You can now proceed to connect!');
                            }
                        }
                    });
                } else {
                    setTimeout(function() {
                       s();
                    }, 3000);
                }
            }
        }, {
            sync: true
        });

    }

    function r() {
        g_network_action = { dataswitch: "0" };

        //l('Turning off...');
        saveAjaxData('api/dialup/mobile-dataswitch', object2xml('request', g_network_action), function($xml) {
            var ret = xml2object($xml);

            //l('Turned off.');

            if(ret.response == "OK") {
                setTimeout(function() {
                    g_network_action = { dataswitch: "1" };

                    //l('Turning on...');
                    saveAjaxData('api/dialup/mobile-dataswitch', object2xml('request', g_network_action), function($xml) {
                        var ret = xml2object($xml);

                        l('Connected.');
                        setTimeout(function() {
                           s();
                        }, 3000);
                    });
                }, 3000);
            }
        });
    }

    login(g_destnation, function() {
        console.clear();
        l('Successfully logged in to dashboard!');
        s();
    });

    setTimeout(function() {
        if($('.error_message').text().length > 1) {
            l($('.error_message').text());
            $('.error_message').hide();
        }
    }, 300);
})();