Identify which android app makes which connection - java

I have been trying to find a way within my android application to determine which app is requesting a connection to the internet (or more formally establishes a TCP connection). Here is an application which already does that.
The above app determines all connections independently without the need of rooting the phone and only with the "Full network access" permission which is magnificent.
I am currently developing with the help of this source, a proxy server on android and I can easily read the connections the phone establishes over the Internet.
How do I determine which application is actually requesting the specific TCP (http/https) connection?

I came in contact with Peter, a developer of the mentioned application and he was very kind to provide an answer regarding in discovering connections.
Here is his answer:
You can find the network information in the standard kernel proc files, like in any other Linux distribution:
/proc/[pid]/net/tcp
/proc/[pid]/net/tcp6
/proc/[pid]/net/udp
/proc/[pid]/net/udp6
/proc/[pid]/net/raw
/proc/[pid]/net/raw6
The [pid] is the process id of your app, but each file holds information about all network connections for the corresponding protocol.

Related

How can I use java sockets to communicate between different networks?

I have java programs for my client and server, and they work fine within the same wifi network. But I need the clients to be able to connect to the server from the open internet. In questions like these
How to connect client and server with the help of ip address which are connected to internet through different wifi?
https://coderanch.com/t/667020/java/Socket-connections-networks
the solution is to manually reroute a port to the server from the router, making it open to connections from the outside. Is there a way to do this with just software on the server? I don't understand why manually dedicating ports is necessary since of course other applications on my computer (like games) that I install communicate with their servers back and forth without me having to manually go in and flip switches.
How can I achieve this with just software running on my server?
If there isn't another way, how do other applications communicate openly without manual router changes, and will opening up ports through my router result in security issues?
You would need to change the architecture of your application. Currently, your server is behind a firewall which blocks connections from the internet - you want this! If you allowed all traffic from the internet to connect indiscriminately to your server, it would be very vulnerable to attack.
Other applications install and communicate without port-forwarding because the developer provides a server on the internet to act as a proxy between clients. The client connects out to the internet which is generally not blocked on home networks. Internal connections going out are considered less harmful than connections coming in.

Can i host my ServerSocket or Java file somewhere on the web?

Heyy guys. I'm writing a chat application in java, works pretty well. But can i somehow host my Server file or the Serversocket on the web? I want to make it so my friends from other pcs can use the client and connect to the server file which is hosted on the web. Is that possible? Can i host the File/socket online?
When you run a java application that opens a ServerSocket, it opens a port on your local machine and starts listening for incoming connections. What you do with those connections is up to the implementation of the java code that you write.
The "web" is much less foreign than you are making it out to be. Your own computer can be on the web that you're talking about and people can connect to your chat service. Or you can choose to host it on something like an AWS server.
The following approach is assuming you are behind a pretty standard NAT config.
Once you run your java application, you need to make sure other computers can see you, either inside your LAN or outside on the internet. You want to start testing from as close to your computer as possible, then start expanding outward.
First you need to make sure that your computer's firewall is actually allowing connections on the port that your java application is listening on.
Opening ports in the Windows Firewall
Setting up and opening ports in Linux
Now computers on your LAN will be able to connect to your java program. Now you need to go one layer out, and port forward your router. This is much less standard so I can't help you too much, but Google can.
At this point, anyone on this internet, knowing your external ip and what port your java application is listening, can connect to your service.
If you chose to host this on an third party hosting service, you'll need to go through similar steps, but there may be slight differences that you can either ask about, or again Google is a great resource.

server registers ip of my modem continously to use it in my android application

Initially, ip-addresses from the ISP are always changing. I am working on an android app and I need to connect from outside my home to my internal network. I need a server connected to my modem/router and the server should save the public ip of my home network every time it changes.
Goal: make a communication between my android app and the modem/router.
My question is:
Do I have to program an app on the server side to do this job, or is there an app already available?
If none are available, could you please tell me the steps to create one, or any references to that end?
Thank you!
I think your best bet is to use a dynamic dns service. That will allow you to give your machine a string name, run the app they'll give you (or many routers support this built-in), and just reference the computer by name when you need it. See http://en.wikipedia.org/wiki/Dynamic_DNS

How to Communicating between a J2ME Midlet and PC?

How do I make a J2ME Midlet to communicate with a java program or some application on the pc through the cable connected?
Incredible_Honk is almost right. The key is to use the (standard) system property "microedition.commports". This provides a comma delimited list of the com ports which are available to your application. To open a connection use CommConnection as follows:
CommConnection con = (CommConnection) Connector.open("com:<commport name>");
Usually this will provide access to a USB serial connection, possibly also infrared if available. Iterate through each one to see which one corresponds to the connection you're looking for.
On Windows at least, you will need to install the correct drivers for your handset first. This will then allow you to open a serial connection and communicate with the application.
There is no general way of doing this. It hardly depends on the capabilities of the mobil. Might be that there is some vendor API giving you special access to USB, but I'm not aware of any.
Some phones support communication via serial port connections.
Take a look at the javax.microedition.io.CommConnection interface for more information.
Sonyericsson phones offer a way to debug your midlet on the device and get the console messages back through the cable.

Communicating between Adobe Air or browser and Java Web Start

We're designing an application and the client has requested that a portion of their app stay in Java Web Start and another portion be in a browser. I'm thinking about AIR as an alternative to the browser because that may give us more features b/c we don't have to stay in the browser security sandbox.
How would I go about having an Air app talk to a Java Web Start app? Do they have to talk through a server? I guess potentially you can just create a socket connection between the two.
You've named the two best options already -- create a socket connection or implement a server API. There are other hackety methods you could use too -- for example, if you're using AIR, you could have both the Java app and the AIR app read/write to a file on disk for communication. This has a host of other issues (file lock when reading/writing) that a socket connection doesn't have, though.

Categories

Resources