B4A Library [Lib] Global Proxy Connector & DNS Changer

Hello everyone :)

This library enables you to connect to proxy servers using Android's VpnService.

*Please use the latest library version 2.0

It will work globally meaning it will work in the background of the user's phone and not just in your application.

How to use :
1- Copy the Jar & Xml files to your internal library folder

2- In your manifest file add the following :
B4X:
AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_NETWORK_STATE)

AddPermission(android.permission.BIND_VPN_SERVICE)

AddApplicationText(
<service android:name="com.b4xcode.proxyclient.LocalVpnService"
   android:label="B4XCode Proxy Service"
  android:permission="android.permission.BIND_VPN_SERVICE">
  <intent-filter>
  <action android:name="android.net.VpnService" />
  </intent-filter>
</service>)
SetApplicationAttribute(android:usesCleartextTraffic, "true")

*You can change the VPN sticky notification service name by changing the following :

B4X:
android:label="B4XCode Proxy Service"
To what whatever you would like.

3- In the Globals sub Add:
Globals:
Sub Globals
    Dim b4xpc As B4XCodeProxyConnector
End Sub

4- Initialize the service :
B4X:
b4xpc.Initialize

5- Then Create the service (it will prepare the VPN to create a profile in the system settings) :
B4X:
b4xpc.CreateService

6- Set the Proxy server IP & Port :
B4X:
b4xpc.SetProxyServer("Proxy Server IP",Proxy Server Port)
Example :
B4X:
b4xpc.SetProxyServer("5.44.54.16",8080)

*If the user is running your application for the first time then he/she will be prompted with the VPN permission dialog to accept the creation of the Proxy VPN profile, once accepted the service will start automatically

-----
7- To Stop the service :
B4X:
b4xpc.StopProxyService

8- To Start the service : You Should only call this method if the service is stopped, or this is not the first time the user started the service.
B4X:
b4xpc.StartProxyService

Complete Example :
Example:
Sub Globals
    Dim b4xpc As B4XCodeProxyConnector
End Sub

Sub Activity_Create(FirstTime As Boolean)
    b4xpc.Initialize
    b4xpc.CreateService
    b4xpc.SetProxyServer("5.44.54.16",8080)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        b4xpc.StopProxyService
    End If
End Sub

Update Version 1.5:
You can now add DNS servers to your proxy connection without any root
Example :
DNS Routing:
Sub Globals
    Dim b4xpc As B4XCodeProxyConnector
End Sub

Sub Activity_Create(FirstTime As Boolean)
    b4xpc.Initialize
    b4xpc.AddDNSRoute("195.46.39.39")
    b4xpc.AddDNSRoute("208.67.220.220")
    b4xpc.CreateService
    b4xpc.SetProxyServer("94.127.212.200",5900)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        b4xpc.StopProxyService
    End If
End Sub

Update Version 2.0:
You can now use the DNS Changer without the need to establish a proxy connection, simple download the library version 2.0, below is the use case example :
After testing and reports, it seems that the DNS service will not run without setting up the proxy connection first.
So you have to set up a proxy connection first then you are able to change the DNS.

Example :
DNS Routing:
Sub Globals
    Dim b4xpc As B4XCodeProxyConnector
End Sub

Sub Activity_Create(FirstTime As Boolean)
    b4xpc.Initialize
    b4xpc.AddDNSRoute("195.46.39.39")
    b4xpc.AddDNSRoute("208.67.220.220")
    b4xpc.CreateService
    b4xpc.SetProxyServer("94.127.212.200",5900)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        b4xpc.StopProxyService
    End If
End Sub

Thank you,
Saif
 

Attachments

  • B4XCodeProxyConnector.zip
    44.7 KB · Views: 173
  • B4XCodeProxyConnectorV1.5.zip
    44.9 KB · Views: 165
  • B4XCodeProxyConnectorV2.0.zip
    45.5 KB · Views: 207
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Thank you very much for sharing, super interesting.

By the way, do you know of some way to change the DNS of the current connection.
I found this application in PlayStore "Change DNS" that works and changes the DNS to navigate, without the need for root.

Thanks :)
 

sfsameer

Expert
Licensed User
Longtime User
Thank you very much for sharing, super interesting.

By the way, do you know of some way to change the DNS of the current connection.
I found this application in PlayStore "Change DNS" that works and changes the DNS to navigate, without the need for root.

Thanks :)
Hello Dear,

Noted, we will look into it right away and get back to you :)

Thank you,
Saif
 

scsjc

Well-Known Member
Licensed User
Longtime User
I know my dear,
We have implemented it with b4a and it's ready using B4XCodeProxyConnector :)

My question is should we implement it in the same library ? :)
I think it would have to be in a library requiring minimum permissions for maximum acceptance
(permissions are not very pleasant to use in google)

eg don't use "AddPermission (android.permission.BIND_VPN_SERVICE)" (if you can)
 

scsjc

Well-Known Member
Licensed User
Longtime User
The library has been updated and we have added DNS Routing :
Update Library Version : 1.5

*Make sure to add the "AddDNSRoute" after the "Initialize" and before the "CreateService"

Enjoy :)
you are a genius :)
 

scsjc

Well-Known Member
Licensed User
Longtime User
The library has been updated and we have added DNS Routing :
Update Library Version : 1.5

*Make sure to add the "AddDNSRoute" after the "Initialize" and before the "CreateService"

Enjoy :)
is necesary create proxy to add/change dns ??? ... ( b4xpc.SetProxyServer("94.127.212.200",5900 )
because i want a change dns only
 
Top