D
D
demon18062019-04-01 13:15:33
JavaScript
demon1806, 2019-04-01 13:15:33

How to pass country code via SOCKS4?

I'm writing a VPN extension that needs to pass the country code over SOCKS4 to the local proxy. How can this be done correctly?

Here is the main file, if anything, to make it clearer:

// prettier-ignore
$(document).ready(function() {
    loadData();
    $("#search").click(search);
    $("#clear").click(clear);

    function loadData() {
        chrome.storage.sync.get(["ip", "port", "countryId", "proxies"], function(result) {
            if (result.ip && result.port) {
                $("#cur_proxy").empty().append("<p>Proxy set - " + result.ip + ":" + result.port + "</p>");
            } else {
                $("#cur_proxy").empty().append("<p>Proxy not used<p>");
            }

            $("#country_id").val(result.countryId || null);

            showProxies(result.proxies || null);
        });
    }

    function search() {
        const countryId = $("#country_id").val();
        if (countryId === "select") {
            alert("Select a country");
            return;
        }


            const proxies = [];
                let ip = "127.0.0.1";
                let port = "1080";
                proxies.push(ip + ":" + port);

            showProxies(proxies);

            chrome.storage.sync.set({countryId: countryId, proxies: proxies}, null);
    }

    function showProxies(proxies) {
        $(proxies).each(function(i, proxy) {
            $("#new_proxy").append('<a class="proxylist" href=#>' + proxy + "</a></br>");
        });
        $(".proxylist").on("click", function() {
            const ip = "127.0.0.1";
            const port = "1080";
            setProxy(ip, port);
        });
    }

    function setProxy(ip, port) {
        const config = {
            mode: "fixed_servers",
            rules: {
                singleProxy: {
                    host: "127.0.0.1",
                    port: port
                }
            }
        };
        chrome.proxy.settings.set({ value: config, scope: "regular" }, null);
        chrome.storage.sync.set({ip: ip, port: port}, loadData);
    }

    function clear() {
        const config = {
            mode: "direct"
        };
        chrome.proxy.settings.set({ value: config, scope: "regular" }, null);
        chrome.storage.sync.clear(loadData);
    }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
ValdikSS, 2019-04-03
@ValdikSS

There is no concept of a country code in the Socks protocol. You can somehow encode it in the authentication login or password, and decode it on the proxy server side and apply different logic.
Browsers do not support VPN. Socks is a proxy protocol, which means you are writing a proxy extension.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question