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: 166
  • B4XCodeProxyConnectorV2.0.zip
    45.5 KB · Views: 207
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Hi good morning
I have been testing, and I have not been able to get it to work, I send an example that I have created following your instructions.

I have tried testing it on a virtual device and on my samsung s8, in both cases it does not work.
The VPN is created correctly and the padlock is correctly placed, but I do not have internet access (with Wi-Fi connection and data connection)
 

Attachments

  • proxy-dns-test.zip
    9.3 KB · Views: 97

sfsameer

Expert
Licensed User
Longtime User
Hi good morning
I have been testing, and I have not been able to get it to work, I send an example that I have created following your instructions.

I have tried testing it on a virtual device and on my samsung s8, in both cases it does not work.
The VPN is created correctly and the padlock is correctly placed, but I do not have internet access (with Wi-Fi connection and data connection)
Hello,

Just checked the library, it seems that it's mandatory to be connected to a proxy server before changing the DNS, we will look into it tonight and update it accordingly :)

Thank you,
Saif
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello,

Just checked the library, it seems that it's mandatory to be connected to a proxy server before changing the DNS, we will look into it tonight and update it accordingly :)

Thank you,
Saif

it's weird, because the application DNSChanger doesn't need to be with a proxy server. directly change dns only and it works.
Thank you very much for reviewing it :)
 

sfsameer

Expert
Licensed User
Longtime User
it's weird, because the application DNSChanger doesn't need to be with a proxy server. directly change dns only and it works.
Thank you very much for reviewing it :)
This library is not based on DNSChanger so their code/approach would be different, this library was built to connect to a proxy server :)

Tonight we will upload a new update that doesn't require the user to connect to a proxy server in case he/she wants to change the DNS only

:)
 

scsjc

Well-Known Member
Licensed User
Longtime User
This library is not based on DNSChanger so their code/approach would be different, this library was built to connect to a proxy server :)

Tonight we will upload a new update that doesn't require the user to connect to a proxy server in case he/she wants to change the DNS only

:)
thanks :)
 

sfsameer

Expert
Licensed User
Longtime User
Hello,

Unfortunately the DNS service will not run without setting up a proxy connection first.
I think in the near future we will release a separate library that will only change the DNS without the need to set up a proxy connection.

Thank you,
Saif
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello,

Unfortunately the DNS service will not run without setting up a proxy connection first.
I think in the near future we will release a separate library that will only change the DNS without the need to set up a proxy connection.

Thank you,
Saif
thanks a lot :) .... in a future :)
 
Anyone been able to get the AddDNSServer function to work? Please provide working example of proxy and DNSServer commands in use. I have been able to get a working proxy connection, but the DNS settings are completely disregarded. I have been able to make a working application using VPNService and change the DNS settings in Android Studio, but was hoping to use B4a to expedite development and add in a few quick extras to the app...
 

sfsameer

Expert
Licensed User
Longtime User
Anyone been able to get the AddDNSServer function to work? Please provide working example of proxy and DNSServer commands in use. I have been able to get a working proxy connection, but the DNS settings are completely disregarded. I have been able to make a working application using VPNService and change the DNS settings in Android Studio, but was hoping to use B4a to expedite development and add in a few quick extras to the app...
Hello,

Please read the first post, it's mentioned there how to use the proxy with DNS Server, but you have set a proxy connection to be able to set the DNS.

*Use Library Version 2, below is the code example :
B4X:
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

We have tested it and it works fine :

Thank you,
Saif
 
I just re-tested your code snippet by copy and paste directly, as well as using custom settings, replacing the DNS with UltraDNS IPs:

156.154.70.3
156.154.71.3

which should show a red page stating "Blocked" for example, if you try to visit "hotbar.com" or "crack4windows.com" - and indicate the page is blocked.

Upon testing, the page goes straight to the actual website and is not blocked (DNS blocks bad domains and supplies IP of block page server) so DNS is not being considered.

Please try connecting with proxy 64.124.38.138:8080 with the DNS above - it simply does not work. I can send you my application code to verify and confirm also that it is not working.

I can code this same app in Android Studio all day long and it works perfectly fine doing what I'm attempting with B4A - only less hassle and it actually works - so something is not right unfortunately.

Then for example, if you add DNS "62.151.180.19" you should be able to resolve a non standard ICANN TLD for ".pi" domains -example "http://app.pi" should reveal a blank page with basic text...

Please test and confirm. I've tested the app on over a dozen devices... all successfully connect to the proxy and adopt the proxy IP address, but no DNS settings stick or are considered by the VPN connection - only the DNS of the proxy server is considered/invoked for name resolution.


**In one of your first statements you indicate that the proxy must be setup BEFORE adding DNS - your code shows you adding DNS BEFORE setting up the proxy - I've tried before setting up the proxy, after setting up the proxy, after starting proxy.. before creating the service... I'm baffled. Will get source together this evening to run by you.
 
Last edited:
Please try the attached demo - The proxy service works perfectly. For some reason, AddDNSServer does not work and the included WebView will not resolve the invoked domain which only exists on the specified DNS server; which is also an authoritative server. Please report back after testing. Thanks!
 

Attachments

  • proxytest.zip
    10.3 KB · Views: 60
Hi @sfsameer This Library still working ? I try my on my side, there are no any error. but just not working.
I can't seem to get it to work either. Has been months since I inquired... Ended up writing our app in Android Studio since we had full control over the code and any issues that could arise. B4A libraries, unless open source, don't allow such and you're stuck with a broken product unless you reinvent the wheel - then, you might as well code the app out entirely...
 

lkching7

Member
Licensed User
Longtime User
I can't seem to get it to work either. Has been months since I inquired... Ended up writing our app in Android Studio since we had full control over the code and any issues that could arise. B4A libraries, unless open source, don't allow such and you're stuck with a broken product unless you reinvent the wheel - then, you might as well code the app out entirely...
Actually I search for solution very long time also.
 

sfsameer

Expert
Licensed User
Longtime User
I just re-tested your code snippet by copy and paste directly, as well as using custom settings, replacing the DNS with UltraDNS IPs:

156.154.70.3
156.154.71.3

which should show a red page stating "Blocked" for example, if you try to visit "hotbar.com" or "crack4windows.com" - and indicate the page is blocked.

Upon testing, the page goes straight to the actual website and is not blocked (DNS blocks bad domains and supplies IP of block page server) so DNS is not being considered.

Please try connecting with proxy 64.124.38.138:8080 with the DNS above - it simply does not work. I can send you my application code to verify and confirm also that it is not working.

I can code this same app in Android Studio all day long and it works perfectly fine doing what I'm attempting with B4A - only less hassle and it actually works - so something is not right unfortunately.

Then for example, if you add DNS "62.151.180.19" you should be able to resolve a non standard ICANN TLD for ".pi" domains -example "http://app.pi" should reveal a blank page with basic text...

Please test and confirm. I've tested the app on over a dozen devices... all successfully connect to the proxy and adopt the proxy IP address, but no DNS settings stick or are considered by the VPN connection - only the DNS of the proxy server is considered/invoked for name resolution.


**In one of your first statements you indicate that the proxy must be setup BEFORE adding DNS - your code shows you adding DNS BEFORE setting up the proxy - I've tried before setting up the proxy, after setting up the proxy, after starting proxy.. before creating the service... I'm baffled. Will get source together this evening to run by you.
Hello,

As the first post states :
1637176755420.png


First connect to a proxy server, then add the DNS.

If you are being blocked as you state then this is a proxy server issue and not the library issue, the library connects to a proxy server nothing else.

I can't seem to get it to work either. Has been months since I inquired... Ended up writing our app in Android Studio since we had full control over the code and any issues that could arise. B4A libraries, unless open source, don't allow such and you're stuck with a broken product unless you reinvent the wheel - then, you might as well code the app out entirely...

This library has been tested and used by a lot of B4X members and it's working without any problems.

If you couldn't get it to work, then please don't use it, this library is free and public and if you can't or unable to use it then don't use it rather than making a statement that has nothing to do with the above issue.

Thank you,
Saif
 
Top