Add proxy settings to my APK using android sturio - android

Hope you are doing well
I have a new project and I need to link it to firebase , but unfortenetlly firebase is not supported in my country
So , I need to find a way to include a proxy to my app , I have a NordVPN account and I hope that I can link it to my project.
I have tried so many codes ;
public MainActivity(String[] MainActivity) {
System.getProperties().put("https.proxyHost", "*****");
System.getProperties().put("https.proxyPort", "******");
System.getProperties().put("https.proxyUser", "******");
System.getProperties().put("https.proxyPassword", "******");
String host = "nl.socks.nordhold.net";
String port = "80";
System.out.println("Using proxy: " + host + ":" + port);
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port);
System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");
Nothing works , please advice
Thank you

Related

Android Orbot malformed reply from SOCKS server

I am trying to enable TOR support on my own XMPP app in android. I am using orbot as TOR proxy and I have the following code to connect app socket:
socket = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 9050)));
socket.connect(addr, Config.SOCKET_TIMEOUT * 1000);
but I am getting Malformed reply from SOCKS server even that my Orbot is up and running. I believe that this error is thrown when app cant access proxy server or mentioned server is not SOCKS proxy.
I have also tried to use jsocks:
Socks5Proxy sProxy = new Socks5Proxy("127.0.0.1", 9050);
sProxy.resolveAddrLocally(false);
String host = account.getServer().toString();
int port = 5222;
System.out.println(host + ":" + port);
try {
socket = new SocksSocket(sProxy, host, port);
}catch(SocksException sock_ex){
System.err.println("SocksException:"+sock_ex);
}
System.out.println("here we are");
where host is "jabbim.com"
But I never get to "here we are" println so it looks like my app hangs somewhere on creating SocksSocket but I am not getting any errors either. When I debug it it hangs on impl.getInputStream somewhere in jsocks (PlainSocketImpl I believe)
Any idea how to fix this?
Thanks in forward
I solved this using
compile "org.igniterealtime.smack:smack-android-extensions:4.1.4"
compile "org.igniterealtime.smack:smack-tcp:4.1.4"
and then connecting using this code:
final Random rndForTorCircuits = new Random();
String user = rndForTorCircuits.nextInt(100000) + "";
String pass = rndForTorCircuits.nextInt(100000) + "";
ProxyInfo proxyInfo = new ProxyInfo(ProxyInfo.ProxyType.SOCKS5, "127.0.0.1", 9050, user, pass);
socket = proxyInfo.getSocketFactory().createSocket(addr.getHostName(), addr.getPort());
by using this you get socket that is already connected to proxy.

Android / Socket.io client - How to send a cookie while handshaking with the server?

I'm trying (unsuccessfully) to connect with a socket.io server, but I keep getting the same errors :
io.socket.SocketIOException: Error while handshaking caused by java.net.ConnectException: failed to connect to my.domain.name.com (port 8080) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused).
I just discovered that I'm supposed to send a cookie with the following values when handshaking : the domain, the path, the name and the value. After trying several potential ways to do it (based on this and this), I ended up with that piece of code, but it still not working :
String cookieString = "domain=" + "my.domain.name.com" + ";path=" + "/" + ";name=" + "auth" + ";value=" + "XXXXXtokenXXXXX";
CookieManager.getInstance().setCookie("http://my.domain.name.com:8080/", cookieString);
String header = CookieManager.getInstance().getCookie("my.domain.name.com:8080/");
final SocketIO socket = new SocketIO("my.domain.name.com:8080/");
socket.addHeader("Cookie", header);
socket.connect(new IOCallback()
{
...
}
CookieManager.getInstance().getCookie(...) keeps returning null and the connection is still failing.
Could anybody help me add a cookie to the header please?
And for the record, I don't know what it could change, but I'm using this lib : https://github.com/Gottox/socket.io-java-client
Thanks in advance for your help !
Mathieu
Ok, just in case anybody would need the solution, I finally fixed this.
It's actually pretty simple :
String cookie = "domain=\"http://my.domain.name.com:80\";path=\"/\";name=\"auth\";value=\"XXXXtokenXXXX\"";
socket = new SocketIO("http://my.domain.name.com:80/");
socket.addHeader("Cookie", cookie);
socket.connect(new IOCallback()
{
...
}
So you just have to create a string of the form "key1=value1;key2=value2..." and to add it as a header to the socket with the method addHeader("Cookie", youCookieString);.
And for the record, I kept getting the error ECONNREFUSED because I was trying to connect on the WRONG PORT (8080 instead of 80)...

Connexion to ftp server with android

i'm newbie on android,
I'm trying to upload file from sdcard to ftp server using android, the code seems to be correct. While debbuging it says that my connet and upload functions to the server can not access the classes given by org.appache.commons.net (no source found in those classes), knowing that i have this org.appache.commons.net jar in the libs foldre, the project build path and the user libraries.
Should i use another librarie or, is there any other work to do ?
The code
public boolean ftpConnect(String host, String username,String password, int port){
try {
mFTPClient = new FTPClient();
mFTPClient.connect(host, port);
mFTPClient.enterLocalPassiveMode();
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
// login using username & password
boolean status = mFTPClient.login(username, password);
Log.w("into the ftpUpload","!!");
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
Log.w("into the ftpUpload","!!");
return status;
}
} catch(Exception e) {
Log.d(TAG, "Error: could not connect to host " + host );
}
return false;}
call this methode in another class using
FtpClient FTP = new FtpClient();
FTP.ftpConnect("..*.", "", "*", 21);
I'm doing it juste like several posts propose it, concerning the lib i added the org.apache.commons.net jar to the lib file and to the java build path..
The exception is given exactly here: mFTPClient.connect(host, port); (btw there are no logs).. Does anybody have an idea what can be the problem with that? I tried lot of codes that works for others but it fail to connect to the ftp server every time. Thanks for your responses.

Acra post script

Tried to use ACRA in my app, but I can't get the google drive or the email working (in google drive I don't know how to create the form from the template, email tells me there is no such email address even though I am sending from the same email address). I would rather get the google drive spreadsheet thing working or better yet - if there is a ready-to-use script for free web host that I can use to get the reports. Anyone knows of such a script?
EDIT: I need a php one...
Looks like ACRA uses a simple post. What language do you need it in? For asp.net:
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder err = new StringBuilder();
foreach (string name in Request.Form)
{
err.AppendLine(name + ": " + Request.Form[name]);
}
TextWriter tw = null;
try
{
tw = new StreamWriter("f:\\errorLogs\\error_" + DateTime.Now.Ticks + ".txt");
tw.WriteLine(err.ToString());
}
catch (Exception) { }
finally
{
if(tw != null)
tw.Close();
}
}
Since you are using a "free web host", the location probably isn't valid for you, but this should at least get you pointed in the right direction. There is another post which is similar to yours. Most free web hosts use php.
EDIT:
Here is a basic PHP script (Not tested, but seems OK to me. My PHP is a bit rusty):
<?php
$file = 'postData.txt';
$arr= $_POST;
$fp = fopen($file, 'w') or die('Could not open file!');
foreach ($arr as $key => $value) {
$toFile = "Key: $key; Value: $value \n";
// write to file
fwrite($fp, "$toFile") or die('Could not write to file');
}
// close file
fclose($fp);
?>

How to access share folder in windows through android and read files

I need to connect from my Android phone to a Windows PC share and access files. I saw some sample apps in Android market that access share folders using smb/samba. But I have no idea about how to create an app like that. Thanks a lot.
You need to get JCIFS and use SmbFile class to interact with files over the network,
http://lists.samba.org/archive/jcifs/2007-September/007465.html
that is a quick example of how to list files, of coarse you need internet permission on. So Far though everytime I try to call SmbFile.listFiles(); I get an UnknownHostException, However others seam to be able to do it with no problem, this might work for you, try it!
Google has released a simple, free Samba client. It is on github so you can have a look and use whatever you need out of that: https://github.com/google/samba-documents-provider
The other option is JCIFS: https://jcifs.samba.org/. There you can find the library and examples on how to use it.
I used JCIFS. Here is an example from my code which reads files from a folder in a windows share:
TreeMap<Date, String> filesInfo = new TreeMap<Date, String>();
NtlmPasswordAuthentication auth = null;
UniAddress dc = UniAddress.getByName(m_dataHostIp);
if(m_userName.length() > 0 && m_password.length() > 0)
auth = new NtlmPasswordAuthentication(m_domain + ";" + m_userName + ":" + m_password);
else
auth = new NtlmPasswordAuthentication(m_domain, null, null);
SmbSession.logon(dc, auth);
SmbFile file = new SmbFile(m_foldername, auth);
SmbFile[] files = file.listFiles();
for (int i = 0; i < files.length; i++)
{
String fileName = files[i].getName();
String extension=fileName.substring(fileName.lastIndexOf(".") + 1);
logInfo(TAG + " " + fileName + "\n");
Date fileTime = new Date(files[i].getDate());
if(m_fileExtension.contains(extension))
filesInfo.put(fileTime, fileName);
}
The code posted above works. It allows you to connect to the share, authenticate (username and password that you know) and get the list of the files. At the root of jcif file access is the SmbFile which has all the info you need to access files in the share. All you need is in your build.gradle for the app add:
dependencies {
implementation files('libs/jcifs-1.3.19.jar')
}
and in your implementation file:
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import static jcifs.smb.SmbFile.FILE_SHARE_DELETE;
import static jcifs.smb.SmbFile.FILE_SHARE_READ;
import static jcifs.smb.SmbFile.FILE_SHARE_WRITE;

Categories

Resources