Skip to content

Proxy Script

Although you can write a script to get the proxy and test it directly while creating a profile, Bịp Studio also supports you to test this script, click on the NETWORK tab, and set the proxy type as Custom. Then open the PROXY SCRIPT tab in the code editor area and start writing your script.

Proxy Script

Proxy Script supports the following functions.

SetResult#

This function is required, no matter how you handle it, you need to call this function in the end to return the result to Bịp Profile.

Syntax
await SetResult (result);
result is an object with the following properties
Properties Description
Type Proxy type, valid values: http, socks4, socks5, ssh
Server Proxy server, including port if available
User Proxy user if available
Password Password if available
Error In case of error, you can put error message in Error attribute, Bip will display error in Status column.
Example
1
2
3
(async function(){
    SetResult({Type: "http", Server: "127.0.01:6969"});
})();

Log#

Display a message in the Status column of the profile which running this script.

Syntax
await Log (text);
Parameters
Parameters Description
text Message you want to display as text

See the examples below.

RandomInt#

Generates a random integer in the specified range.

Syntax
RandomInt (min, max);
Parameters
Parameters Description
min Range start
max Range end

Example

1
2
3
4
(async function(){
    const r = RandomInt(10, 100);
    Log(r)
})()

RandomArray#

Randomly retrieve an element from an array.

Syntax
RandomArray (array);
Parameters
Parameters Description
array Input array

Example

1
2
3
4
5
(async function(){
    // const r = RandomArray(["a", "b", "c"]);
    const r = RandomArray([1,2,3,4]);
    Log(r)
})()

Delay#

Delay a specified amount of time.

Syntax
Delay (ms);
Parameters
Parameters Description
ms Delay time in milliseconds

Example

1
2
3
4
5
(async function(){
    Log("Stop for about 2 seconds!!!");
    await Delay(2000);
    Log("Share this tool please!");
})()

HttpRequest#

Make an HTTP request, useful when you want to integrate a proxy through an API from a 3rd provider.

Syntax
await HttpRequest (url, data, timeoutMS, headers);
Parameters
Parameters Description
url Link to send request to
data Data sent in POST method
timeoutMS Time limit in milliseconds, if the server does not return the result after the time limit, it will return a timed out error
headers Custom HTTP header

Return result

An object with properties illustrated as follows

{
    "status": 200, //http response code
    "headers": "raw response header",
    "body": "response body",
    "error": "", //error in case of occurrence
}
Example
(async function(){
    /*
    Suppose the bip-proxy provider has an API http://bip-proxy.io/get-proxy?key=XXX where XXX is your API key.
    The bip-proxy server will return the following JSON result

    OK => {"ok": true, "type": "http", "server": "12.234.56.89:6969"}
    Error => {"ok": false, "message": "Server is overloaded, please try again in a few minutes!"}
    */

    Log("Getting proxy from server...");
    const res = await HttpRequest("http://bip-proxy.io/get-proxy?key=XXX");
    if(res.error) { //If there is an error during the request execution (network failure, timeout...)
    SetResult({Error: res.error});
    }
    else {
        const json = JSON.parse(res.body);

        if(!json.ok) //If something went wrong
            SetResult({Error: json.message});
        else
            SetResult({Type: json.type, Server: json.server});
    }
})();

ReadFile#

Read data from a file as text.

Syntax
await ReadFile (file);
Parameters
Parameters Description
file Path to the file to read

Returns: Text data or null if there is an error

Example
(async function(){
    /*
    Suppose you have a text file in D:/proxies.txt with 3 proxies and you know it is HTTP

    11.11.11.11:1111
    22.22.22.22:2222
    33.33.33.33:3333
    */

    //Read data from the text file and convert it to an array
    const lines = ReadFile("D:/proxies.txt").trim().split("\n");

    //Get a random line.
    const randomProxy = RandomArray(lines).trim();

    //Return the result to the tool
    SetResult({Type: "http", Server: randomProxy});
})();

RootPath#

This is a constant that indicates the current path that Bịp Profile is running on.

Example
1
2
3
(async function(){
    Log(RootPath);
})();

BipGlobal#

A global object that exists since Bịp Profile is started until you exited, accessible from any profile globaly.

Example
1
2
3
4
5
(async function(){
    if(!BipGlobal.data) BipGlobal.data = [];
    BipGlobal.data.push(RandomInt(0, 10));
    Log(BipGlobal.data.join(","));
})();

Profile#

An object that contains information about the profile that is running the script, including:

Properties Description
Id Id of the profile (can be seen in the ID column)
Title Name of the profile
Index Order of the profile in the list (can be changed if you sort the profile list)
Example
(async function(){
    // Log(JSON.stringify(Profile));

    /*
    Going back to the ReadFile function example above,
    now suppose you have 3 profiles and want
    profile 1 to run the first proxy
    profile 2 to run the second proxy
    profile 3 to run the third proxy
    */

    //Read data from the text file and convert it to network format
    const lines = ReadFile("D:/proxies.txt").trim().split("\n");

    //Return the corresponding index of the profile running the script
    const proxy = lines[Profile.Index];

    //Return the result to the tool
    SetResult({Type: "http", Server: proxy});
})();

Once you have written your script, you can set up your profile in the proxy options when creating or updating a profile.