Adding an android phon to a DNS server? - android

I want to know if it is possible and how to, make an application, that allows me to put my android phone in a DNS server, as we do in a Windows PC. I want to identify my android phone by a name in a DNS network, obviously in a network in which there is a DNS server.
Thanks in advance...

Generally, you have three options:
Static IP. Sometimes it's possible to get a fixed IP for your phone, in this case you need to setup a DNS record only once, and it requires no software nor configuration on the phone itself. All you need is just create a regular DNS address record. (Consult your DNS administrator (or ask on superuser.com if your need help))
Home/office network (DHCP). If you want to access your phone via LAN, and this LAN have a DHCP server under your control, DHCP server can be configured to update a DNS record whenever your phone connects. In this case too, the phone does not need any special configuration/software - it's a DHCP server which needs to be configured.
Dynamic DNS. Your phone can submit it's address via dynamic DNS. This will work for any case - LAN (including NAT) and cellular connection. You usually need to subscribe to some dynamic DNS service for this and yes, there are dynamic DNS clients for Android. Try net-me.net guide on setting up dynamic DNS under Android (I am affiliated).
(For what purpose you want access your phone, which software will listen to incoming connections, and if the phone IP will be accessible from anywhere - it's all a completely different story.)

If your DNS and DHCP servers support it, you can get the DHCP server to automatically update the DNS server. See http://technet.microsoft.com/en-us/library/cc787034(v=ws.10).aspx for a description of how to do it with Microsoft's servers.

Related

ssh through tethered android phone to AWS EC2 server

Disclaimer: I don't know this is the actual problem, I just suspect it is.
I have set up an Amazon Web Services EC2 instance as a remote git server. I have had to configure it to only accept incoming traffic from a single IP address though I had wanted to make it open to all because I will be using it while I travel.
The complication here is that mobile phones cannot have a static IP address and I will be accessing the server using my android phone tethered to my laptop. This means I have to make a new rule to accept traffic from my current IP address before connecting to the server via ssh.
When setting this rule there is an option to use "My IP Address". Amazon automagically checks my current IP address and sets it in the rule. It looks like 123.123.123.123/32. The "/32" part there being the actual end of the address.
When testing the server from home I have no problem accessing the server from my desktop computer over the home network with static IP. Equally no problem accessing the server from my laptop computer over the home network. I then tethered my phone to my laptop and tried to access the server via the cellular network with the home static IP address rule still in place. As expected the connection was not made because the phone is allocated a different IP address.
BUT...then I go out for a day of coding in a nice location and try to connect to the server and it does not work. I went in to my EC2 console and set a new rule to accept traffic from my current IP address over my tethered phone using the automagic "My IP Address" setting. Then tried to connect to the server via ssh. No joy.
The connection is not made. Just times out in the same way it did when I originally tested trying to access from an IP address not specified in the rule.
So I was thinking it has something to do with ports. Is that what the "/32" above is? Or have I got that all out of whack?
What can I do to gather more information to help define what the actual problem here is?
I had this same problem connecting to a Postgres database in AWS. Here is what I did to solve it:
I opened up the server to everyone 0.0.0.0/0
I went into the server and determined my actual ip address that it was trying to connet with.
Went back and fixed my rule with that IP address.
My automatically populated IP address was different than the actual one.
Find an Android VPN provider that will sell you a static IP for every use. That might be a way to use a static IP as a security measure. If the VPN provider offers the service on PC as well you can set both to the same IP. Your really ambitious you could set up a VPN service on your virtual machine and then configure it to only except connections from it's self via SSH. You would have to Adjust your "security group" to except VPS connects from any where. The second method would mean that you wouldn't need two static addresses for and added layer of security.

How to find all the esp8266 connected to a router

Hi all I want to connect multiple esp8266 devices to my router and create a mobile app that can find those devices and send messages to them using udp.
Currently my plan is to let esp devices listen to a port and then my app would send a message on that port, esp would respond and the app will store the IP.
Is there any better way to do that?
A friend of mine told me that this approach will fail if routers's gateway is changed. Is it true?
I am just calling WiFi.begin(Ssid, Password); to connect to wifi without doing any changes with wifi.conf().
I am using arduino SDK.
Give your ESP8266 devices a static IP addresses so the mobile app will know in advance where they could be 'found':
IPAddress ip(192,168,1,xx); // desired static IP address
IPAddress gateway(192,168,1,yy); // IP address of the router
IPAddress subnet(255,255,255,0);
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
and use dynamic DNS service (unless you have a static IP address) with port forwarding to access each of the ESPs. You can choose ports 8266, 8267, 8268, 8269, ... or any other above 1024 and then set the port forwarding in your router settings so port 8266 will be forwarded to the IP address of your first ESP and port 80 (or any other), port 8267 will be forwarded to the IP address of your second ESP and port 80 etc.
Afterwards you can access your ESPs from mobile app (or internet) using URLs looking like http://xx.xx.xx.xx:8266, http://xx.xx.xx.xx:8267, http://xx.xx.xx.xx:8268, http://xx.xx.xx.xx:8269, ... or by using dynamic DNS service with: http://myhome.something.com:8266, http://myhome.something.com:8267 etc. Or you can access them from your local network by known static IP addresses. That is - your mobile app will have to determine if it is inside local network or not. Or you can always access ESPs using proxy - in that case the URLs will not depend upon being inside or outside the local network.
Your friend may have more of the details of your solution, but IMO the gateway has nothing to do with it. If all clients and the server are on the same subnet inside the router's local network then the gateway doesn't come into play.
I would do a UDP multicast. Your mobile app would just need to send one request and then listen for replies from the ESPs for a few seconds.
One way is to check all the Mac addresses on the network. The first 6 digits is the unique code for the company that made the wifi dongle.
This is assuming you do not have any other devices on the network using the same dongle and aren't what you're trying to search for.
You can find all the Mac addresses on a network by performing an ARP request on each IP.
But all the devices would have to be on the same subnet.
If you devices are remote, then I would go with your original plan, however your friend is correct if the gateway changes this would require something a little more robust. Use a Dynamic DNS service along with a domain name. The Dynamic DNS will update your DNS records in almost real time if your gateway address changes.

ActionScript 3.0 How to properly connect? "localhost" or "192.168.XXX.XXX"?

I am struggling with this for three days now. It is an android client application that connects to the server AIR application through Wifi on local network.
I need my application to connect to the server every time it is launched without asking the user to enter local IP, in case it changed.
It seems there are many ways to make sure the connection is successful, but I want to make sure I can go without the help of RTMFP or PHP or SharedObject stuff.
I am able to get local IP using NetworkInterface and NetworkInfo ANE from Android client. Then I use the variable to
mySocket.connect(ipAddress, 8888);
But there is a problem:
1) When debugging on Android via Wifi
The detected IP 192.168.137.2
2) When debugging on Flash, on computer
The detected IP 192.168.137.3
So, the local IPs are not the same. So client fails to connect. Everything works perfect, if I manually set that IP, but I need a code that works, even if the IP on local network changed.
As I mentioned making a textInput field in case IP changed and ask the user manually enter IP is not an option.
My question is why using "localhost" as host parameter of socket.connect(host, port) does not work? If it did, there would be no need for detecting local IP at all. "localhost" works for me only if the client is running on computer, but not Android.
Is it the problem with Security Policy file? if so, I have no idea how to use that. I can't find any tutorial on that.
You have two devices
1. Android device running an app and acting as a client
2. Computer running an AIR app and acting as a server
Each of those devices will have it's own IP address on the network. In your case android device IP is 192.168.137.2, and computer IP is 192.168.137.3.
In order for client to connect to server there must to be some means of delivering server IP to the client. Normally for an app like this you enter server IP address manually in settings, or have one central place available on the net where server registers it's IP address and client fetches the address from there.
Since you don't want to use any of these options the last resort would be implementing local area network scanning. Where you scan all the segment 192.168.137.* and search for opened port reserved for server. That of course is not good implementation but could work if project is for your own use.
Lastly "localhost" is name mapped to loopback IP 127.0.0.1 which is special address and is used to connect to the same device app is running on. In your case if android app is connecting to localhost it is trying to connect to the android device itself.

How to communicate without prior knowledge of IP

Im developing an app which uses the tcp connection. currently im communicating using hard coded IP addresses as a sample, but in the real world this is not the case i think. We come across any mobile and start communicating/sharing etc without having any prior knowledge of other person's IP. In such a case how to get the IP address of those who are using my application. How can i communicate without the prior knowledge of the IP address. How to implement this. Help me in sorting it. Thanks in advance.
EDIT:
And in case if the user connects the internet thro' GPRS/3G connection then his IP address will be changing based on the service provider. How can i find that.
Given what you are commenting on other answers, if what you want are the IP addresses of other Android devices to do some kind of P2P game you should note that there is no reliable way to do that directly.
If the users are connected in the same LAN you could provide in your application some kind of discovery service using UDP broadcasts.
If the users are connected to the internet and have public IP addresses then you could use some intermediate server to register the users at startup and have them discover other users using that server.
But (and this is the most common case) if the users are connected to the Internet and have private IP addresses (like when they are connected with WIFI on their LAN) you need some kind of server that acts as a proxy for their requests because there is no way to make a direct TCP connection from a natted IP to another natted IP. There are a few solutions to solve this problem, you could start for example by learning something about XMPP and how it works.
Your app must use DNS. You will first need get your IP into the DNS system. You do this by signing up for a domain name & setting up A / AAAA records for hostnames with a hosting provider (or you could set up your own DNS server). You may even find some free DNS providers.
In your app, you can hard-code a fully qualified domain name that you previously set up, say - app.foo.com and use the android gethostbyname library call to fetch the IP address for you. The local DNS resolver will then go to its DNS server and fetch the IP address corresponding to app.foo.com.
Can you use DNS? You can still hard-code the domain name if you want, and the domain name can be configured to point to any IP addresses anytime later.

Using Android phone as wifi web server

I got this crazy idea that I don't know is possible or not... what I want to do is set up my phone as wifi access point, then allow people to connect to it, but handle all incoming http traffic myself.
So:
phone wifi in access point mode; open wifi network (this tidbit works - yes I know it's not officially supported but then I have no intention to distribute put this app on the open market or so, it works on my phone and that's good enough for me).
client can connect to the phone (e.g. my laptop: this also works).
when client tries to open an http connection to any random server, this has to be intercepted by my app and handled by a local web server. This is the point that I'm stuck on.
The web server part shouldn't be too hard; there are (open-source) web servers available. But getting the traffic to that web server, there is the problem.
The behaviour I'm after is a bit similar to what you get when connecting to some open hotspot, like hotel hotspots, that then redirect you to a login page. This intercepting of the connection request (I suspect I have to look at DNS requests?) is what I'm after.
I have seen an app that is doing this but they require the phone to be rooted. I'm hoping to find a way to do it without rooting the phone.
Wifi hotspots would usually use IPTables to redirect port 80/443 traffic to a local web server.
I have run squid on linux machines in the past on port 3128, then sent all port 80/443 traffic to squid. Then I used squid redirect any url that I didnt explicitly allow to a local web server.
IPTables is accessible on rooted android devices only though.
And I doubt there are many proxy servers available on android, so you would have to send HTTP traffic to a proxy server over the network connection.
Like has been said, you'll need IPTables, but you'll also need a proxy server, like Squid.
Google "transparent proxy with squid", or check here:
Linux: Setup a transparent proxy with Squid in three easy steps
you do not need to have a proxy, you just need a full LAMP stack on your device and IPtables, you can mark all packets that have not been authenticated to forward through to your local page, then using php change the rule for that IP address once the address has authenticated, you could do the same for mac addresses if you wish, you would then also need a daemon that periodically reset each exception

Categories

Resources