I use this Tutorial to Make PPTP VPN Connection Programmatically And Capture Packets
But Some thing is wrong, i think problem is when i want cature pockets in while loop
when i Connect to vpn by app and try to open site in browser it shows : You are offline ...
Send And received always is 0 bytes / 0 pockets
also i need to disconnect connection in app
how i can fix them ?
The tutorial you used is not about PPTP or another specific VPN kind, it's about packet capturing. You should implement PPTP client side by yourself and after that interconnect you packet capture code (while loop) and PPTP client code.
If you can show your source code it would be easier to show what's wrong.
UPD1:
so how i can use PPTP connection, connect and disconnect it ?
This is a big and complex task. There is no fast solution. When I did the same I've spent about a year for it. You can do something like the following:
Import existing 3rd party PPTP client into your project (for example, http://pptpclient.sourceforge.net/)
Improve imported code to make it able to interact with your main code (C/C++ code you can use as native library via JNI or as external executable and interact with it via IPC)
Link your code with imported code (read IP datagrams from VPN service socket, write them into PPTP client socket, and vice versa)
UPD2:
I saw two applications which implement VpnService.
The first one is StrongSwan. VpnService extended here, native part (real vpn service implementation) starts here.
The second is OpenVpn port ics-openvpn. It starts standalone openvpn process here, and manages it via standard openvpn management interface (unix socket) here.
Related
Socket programming question here.
My interface comprises of an Android device(client), A wireless module hosting an access point, and an Arduino Uno(server).
My Android client class works when 1 user connects and sends commands to my Arduino server class.
I want to make my program friendly to many users at the same time. My server will only read in values from 1 connected client at a time.
After some research I've found that Arduino does not allow multithreading naturally, which is why i've decided to look into a number of libraries.
The Arduino library that I've decided to use for this specific issue is protothreads. Unfortunately, i've been unable to find any examples of creating a server with Arduino to accept a client's commands. Furthermore I'm having a lot of trouble figuring out how to make this library work in my favor.
Now for my question,
How exactly can I allow my Arduino server to constantly listen for
incoming messages from more than 1 client device?
Or is there something I can do on the client side that would make this communication possible?
Could you get away with accepting the socket responding and the closing it. Similar to a web page. As not to have multiple sockets open at once. Note uno only has 2k of ram flash goes quick. By one and close each stands alone and naturaly allow many different connections. Just one at a time.
In ToyVpnService they read IP packets and then forward them to a remote VPN server.
Why do they use DatagramChannel? Isn't DatagramChannel used with UDP only?
Why do they forward packages with their IP and TCP headers? There are a lot of examples of writing arbitrary data to sockets (for example, here) without headers.
From what I can tell the ToyVpnService is either an experiment or in a very early stage of development.
Yes, it's only used for UDP. They either don't care about lost packets at this stage or they plan to implement a control mechanism later.
In the messenger example that you provide, the apps exchange strings. They don't need to send any other info because they only want to display them. When you communicate with a VPN you have to send the headers so the VPN can forward any data it receives.
I'm trying to develop a proyect like PTTDroid, I mean a Push-To-Talk or Walkie-Talkie application.
The issue is that in this app you canĀ“t use 3G to access the web, so I've decided to use a Node.js server and implement an Android client to comunicate with it. I tried to do a multiplattform proyect using Phonegap the problem is that for audio record you can't access to buffer, you can only start and stop or pause the recording process but not send data while capturing. So my problem is that is possible to streams audio capture in real time by native Android functions (Audiorecord class) with a Node.js server by Socket.IO or similar?
I discovered this project, Asimi JS, but I don't know if someone else knows a better way to do what I want.
Thank you very much for your help!
It is certainly possible to do it, but a standard NodeJS http server would not be advisable as it uses tcp. You want to use UDP as a transport layer for audio, since it will be faster and the small packet loss that can occur will most likely not be a problem.
To be completely honest with you it sounds like you need to write a few demo applications on the native platforms - so do not use phonegap. You need native platforms in order to access things suchs as the mircrophone and to stream over UDP.
When you have a demo working, you can go on and try with another platform afterwards, but start with a simple setup instead of trying to do it all at once - if it was that easy, someone else would have done it before you.
Let me recommend a simple UDP server in whatever language you are most comfortable with such as (NodeJS, Java, C, C++, C#). Let the UDP server receive and save the content into a file that you can then play back on a desktop computer to verify the result. As a simple client, build one either on Android or iOS, and stream a file that you have already recorded and included in the app. When you have this setup working, you can try to capture the microphone, then do a user interface, then support multiple phones, then build a server which records the conversations, then build a user database, and so on a so forth. But start with a prototype of your main feature.
I've finally discovered and solved my problem (at least that's what I think)...First of all I created a server to send and receive UDP packets by DatagramSocket and after that, to achieve communication between server and client, when I was connected by 3G, I needed to have a static port and IP, that's why my server couldn't connect with the client. With data connection, the user IP and port is not always the same and you have to keep the same socket always opened if you want to send and receive. On the other hand the server has to store the adress and port from the client in the moment of connection.
Thank you very much for your help ExxKA
I want to develop a client server application in which server is on PC having wifi and client application in on android phone. I want to make server application using vc++.Net and client application in android. I am newbie in network programming and i am unable to find any clue about this on internet. And I also don't know is it possible that server is made using vc++.net and client is made using android.
Can anybody please direct me how can i move for this. And if possible please provide me some links related to this.
Any help will be appreciated.
Your question is vague and open to a lot of potentially "correct" answers. First of all, the whole wifi v.s. internet part is irrelevant, you just want to communicate from your Android devices to your pc over the network.
The term to look for is sockets. What you do is listen to particular port on the PC (the "server"). You'll have to open up the relevant ports in the firewall.
You then write an android app that communicates with this server, see here for a proper introduction.
There is no problem using a single socket (ip address + port) to connect with multiple devices, as long as your protocol includes a way for each client to identify itself.
...
That said, you can also do all of this at a higher level, running a SOAP/JSON-based client/server scheme (as opposed to writing your own socket-based protocol). See http://wiebe-elsinga.com/blog/?p=405 for an example.
What is the most appropriate choice depends on your exact requirements (performance, deployment) and your level of experience.
Update
You can use jmDNS to achieve this. It's a really helpful library and once you detect the all devices connected to the same wifi you can get their ip and port so you can establish a connection. You can learn more about how to use it here.
Or you can use Android Wi-Fi Direct API which works only for API Level 14+. Here is more information about the API : Wifi-Direct.
how to achieve transfer file between client and server using java socket
Hope it is what you are looking for! : )
I need to monitor the VPN traffic i.e. I need to read incoming and outgoing VPN traffic.
For this, I am trying to create my own VPN client, but I did not find any working example of "android.net.VpnService", I looked at android sample application ToyVpn, but it is not working, I'm getting following exception:
E/ToyVpnService(2302): Got java.net.PortUnreachableException:
E/ToyVpnService(2302): Got java.net.SocketException: sendto failed: ECONNREFUSED (Connection refused)
Also, it is not mentioned anywhere, "how to set username".
It read that we can use hidden APIs but this will require root access, right now I don't have a rooted phone...
What I want to ask about this (hidden APIs) approach is that, the apps which use hidden APIs, do they create their own VPN client or uses the android's default client? And if they use android's default client then is this still possible to read the incoming and outgoing traffic?
I am seeking some guidelines, or a working example, about creating my own vpn client using "android.net.VpnService".
I need to monitor the VPN traffic i.e. I need to read incoming and outgoing VPN traffic.
Unless this is your own VPN implementation that you hacked a backdoor into, this had better be impossible, for obvious security reasons.
I'm getting following exception
Off the cuff, my guess is that you are not running the ToyVPN server component, or it is not reachable from your test environment. However, it has been quite a while since I played with ToyVPN and I am not an expert on its code base.
Also, it is not mentioned anywhere, "how to set username".
I do not recall ToyVPN having the concept of a "username".
It read that we can use hidden APIs but this will require root access
Hidden APIs have nothing to do with root access.
do they create their own VPN client or uses the android's default client?
You would have to ask the authors of whatever apps you are referring to.
And if they use android's default client then is this still possible to read the incoming and outgoing traffic?
Only the "incoming and outgoing traffic" that they generate. It should not be possible to spy on other apps' VPN traffic, for obvious security reasons.
I need to monitor the VPN traffic i.e. I need to read incoming and outgoing VPN traffic.
That's something of an ambiguous question, because the VPN has an incoming and outgoing stream, and should implement an incoming and outgoing tunnel stream.
For a conventional VPN you'll have to coordinate both; on one hand setting up a tunnel connection to a VPN server and writing the input stream of the VpnService's interface into the tunnel output stream, and on the other hand writing the tunnel response back into the interface output stream.
Contrary to what Mark states in his answer, you do get the raw network requests as the input stream of the VpnService interface. Bear in mind that you're getting the raw bytes that would be communicated over the network interface, so you'll actually have to go out of your way to parse the IP packet and its TCP or UDP payload.