How to get hostname by pinging a IP Address Java in Android Studio - Java for Android App Development

Hello everyone,
I'm making a IP Scanner app in Android Studio. I have successfully checked if a PC in my LAN is Alive or Dead. But I also want to show the PC name against the IP Address.
I searched on Internet and all the solutions I found just return me the IP Address but the hostname like.
Code:
InetAddress inetAddr;
inetAddr = InetAddress.getByName(host.hostname);
String hostname = inetAddr.getHostName();
String canonicalHostname = inetAddr.getCanonicalHostName();
I also tried to execute ping -a [IP Address] in Android Terminal that also returns me IP Address not Host Name.
But If I do ping -a [My Local IP] than it returns local-host but for all other IP's it doesn't work.
This is also not a DNS issue as someone suggested on Stackoverflow, because on my windows 7 machine I'm able to resolve the hostname using ping -a [IP Address]
Both my windows machine and Android phone getting their IP from DHCP and all other settings like DNS, Gateway are same for both devices.
This was fairly easy in .Net as I have created a IP Scanner in .Net, but in Java I haven't found a solution for this yet.
Hope someone will provide a solution
Thanks

Related

Using a Port other than 3389 for Terminal services ?????????

Hi,
Is it possible to use a port other 3389 with the Terminal services client?
Or is this hardcoded into the client ?
Thanks
Rob
No its not possible. Also the server always runs on port 3389.
lutzs said:
No its not possible. Also the server always runs on port 3389.
Click to expand...
Click to collapse
REALLY!
Please explain ? As we run a multiple server network with Terminal services running on various port from 3385 up to 3399. We also change the default port on our workstations (XP prof) from 3389 This a well documented item. You then specify in Terminal server client:- IPORT. Example: 84.234.456.789:3396. Use it everyday!
Rob
two ways that you can do this:
1: on the host machine, regedit to here:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Control\Terminal Server\WinStations\RDP-Tcp
Find "Portnumber" and open. Click on "Decimal" and change to the desired port. The PC will now listen on your specified port number for incoming terminal service requests.
2: If you have a router you can use port redirection. (virtual servers etc)
Specify the ext port number (eg. 3390) then the int port number (3389) then the IP address of your target PC. This will redirect all traffic recieved on port 3390 to port 3389 to your specified internal IP address.
To access remotely for example using remote desktop connection, enter your IP address (or dynamic DNS address) followed by :3390
Hope this helps
J
Thanks Codiac,
So you can't specify the port in terminal services client connection box (as per a Full size PC runing XP Prof) only as a registery change.
Your piccy is right, you can enter IP addresses followed by a port number.
eg: 81.33.44.55:3399
The problem with, for example XP Pro is that it will only listen on 3389 by default, the registry change is necessary if you want to access more than 1 PC on a network.
As per your piccy, once you have edited the registry to a chosed port, the PC will then listen on that port (eg. :3390).
I personally use Option 2, this requires no change to the registry of a PC, the router does the redirection for you.
for example:
PC 1 = 192.168.0.1
PC 2 = 192.168.0.2
To access PC 1 allow a rule in the router to pass port (external) 3389 to (internal) 3389 to 192.168.0.1
To access PC 2 allow rule in router to pass port (external) 3390 to (internal) 3389 to 192.168.0.2
this way, when you open the remote desktop connection client and enter say, 81.44.231.22:3390 the router will see 3390 and redirect it to 3389 straight to 192.168.0.2
Hope this helps
J
Hi Codiac.
I think I'm confusing you here. Port change, at the host is not the problem. Either by router redirection, or registry edit of the listening port of the HOST. Its the CLIENT in Win mobile 5 wont let you specify a port when connecting to a host. You can with a registery edit of the Win mobile client on the Pocket PC, change the port, but not at connection IP 'time'
Rob

[Q] Help me access my server over the internet

I want to visit this page on my server
http://192.168.2.53:8080/tma/majBtm/androidToDesktop
Since it's a dynamic IP, the above mentioned IP address keeps changing everytime I reset my connection. I replaced the IP with a DynDNS hostname I created
http://tmagrails.dyndns-ip.com/tma/m...droidToDesktop
However, I'm unable to access this page from a remote machine (any machine outside the server's network)
I was asked to forward the port 80 to 8080. I'm unable to do so as there is no port forwarding option in my router page. I use a UTStarcom UT300R2T modem/router.
Is there any workaround for this?
Please advice.
blueren said:
I want to visit this page on my server
http://192.168.2.53:8080/tma/majBtm/androidToDesktop
Since it's a dynamic IP, the above mentioned IP address keeps changing everytime I reset my connection. I replaced the IP with a DynDNS hostname I created
http://tmagrails.dyndns-ip.com/tma/m...droidToDesktop
However, I'm unable to access this page from a remote machine (any machine outside the server's network)
I was asked to forward the port 80 to 8080. I'm unable to do so as there is no port forwarding option in my router page. I use a UTStarcom UT300R2T modem/router.
Is there any workaround for this?
Please advice.
Click to expand...
Click to collapse
This IP Address is a local-only IP address.
IP addresses in the 192.168.x.x ranges cannot be accessed from the internet.
You need to port forward a particular port on your router, and map that to the internal address. Your router has an external facing IP address, and you need a router that supports DynDns in its control panel.
You can find your external IP via www.whatismyipaddress.com but to get this working you need to be able to setup an incoming port forward, so port 8080 is directed by your router to your PC. The DynDns is currently pointing to
tmagrails.dyndns-ip.com (117.192.174.157)
So you just need to somehow forward all incoming connections to port 8080 onto that desired computer, and give that machine a static IP address on the internal network via DHCP pre-allocation.

How to connect to your Raspberry Pi from from outside, behind NAT with SSH tunneling

original source
To do this, you will need a server or vps with ssh enabled and a public ip address,
what we are going to do is to use the server as a tunnel to your Raspberry Pi like this:
Code:
Raspberry Pi ----> SERVER <---- A computer outside your home network
To make everything easier, configure your server to use public key authentication, so you
are not going to be asked for a password everytime you connect.
First of all, put your ssh key inside ~/.ssh/ BOTH of your raspberry and the computer you
want to use to access the RPI, then we we'll configure the server to tunnel connections
to the bind address we specify, so edit your server /etc/ssh/sshd_config and add at the end:
Code:
GatewayPorts clientspecified
Now we are ready, open a screen session on your raspberry and type:
Code:
ssh -R your-server-interface-ip:2222:localhost:22 [email protected]
So, if you want the SSH port to be tunneled only on the server localhost, you shall type:
Code:
ssh -R localhost:2222:localhost:22 [email protected]
Otherwise, if you want it to be tunneled on the public ip address:
Code:
ssh -R your-server-address:2222:localhost:22 [email protected]
Now you are ready, if you used the localhost bind interface, you can reach your RPI connecting
to your server and then, from the inside of the ssh session type:
Code:
ssh -p2222 [email protected]
Else, if you choose the public ip, you will simply connect with:
Code:
ssh -p2222 [email protected]
Enjoy ^_^
Dynamic DNS
Your home connection may not have a static IP address, so most home routers now give the option of filling in dynamic DNS account information that will assign a hostname to your IP address automatically. This means you don't have to keep track of your IP address manually.
Google for "how to set up dynamic dns" -- Wired.com has a nice step-by-step tutorial. (Can't post links yet. :-/) I use DynDNS as my provider, they allow you to set up a hostname using their domains for free.
=RV=
redvelociraptor said:
Your home connection may not have a static IP address, so most home routers now give the option of filling in dynamic DNS account information that will assign a hostname to your IP address automatically. This means you don't have to keep track of your IP address manually.
Google for "how to set up dynamic dns" -- Wired.com has a nice step-by-step tutorial. (Can't post links yet. :-/) I use DynDNS as my provider, they allow you to set up a hostname using their domains for free.
=RV=
Click to expand...
Click to collapse
Considering in this tutorial i've suggested a dedicated server as tunnel, i don't get why static/dynamic ip address of your home network is important ....
control rpi over nat by http
The hopmsg.com allows you the make a free message channel by creating a random key for free (no registration,login,etc) which can be used to get status / send command to your rpi:
1, Simplest way to Send/Receive message from any kind of OS/browser/platform just by clicking on a link, only need to know the ID of your msg!
Example: set your message by opening a link : hopmsg.com/ctl.php?id=YOUR_UNIQUE_KEY&value=message
get your message from any device by opening: hopmsg.com/ctl.php?id=YOUR_UNIQUE_KEY
or use the Android App to get/set it.
2, Control your device inside Nat/Lan
Example: set your command by opening a link : hopmsg.com/ctl.php?id=YOUR_UNIQUE_KEY&value=command
get your command from any device by opening: hopmsg.com/ctl.php?id=YOUR_UNIQUE_KEY
or use the Android App to get/set it.
3, Basic monitoring system
Bash script checking uptime:
UP=`uptime | sed -e 's/ /_/g'`; curl "hopmsg.com/ctl.php?id=YOUR_UNIQUE_KEY&value=`echo ${UP}`"
and use the Android App or a browser to check the status of the device.
4, Get your IP address, the message source, poor man's dyndns
If you set some values, with src=1 parameter your IP and the UTC time also added to your message
Example:
hopmsg.com/ctl.php?id=YOUR_UNIQUE_KEY&value=VALUE&src=1
wget -qO- hopmsg.com/ctl.php?id=YOUR_UNIQUE_KEY > result.txt
to use with some script.
Hi,
another option is dataplicity , very easy installation , 0 configuration and really good features

No DNS Server / port forward to port 53 on Android 4.4.2 w/root & WiFi Tether Router

No DNS Server / port forward to port 53 on Android 4.4.2 w/root & WiFi Tether Router
I tried everything I could think of before posting this. If this is the wrong location for this kind of issue please let me know.
Anyway...
I have a rooted phone (Samsung Galaxy Avant) running the stock Android 4.4.2 that came with the phone and I use WiFi Tether Router to provide my other devices with an internet connection. Everything works perfectly and I get very fast LTE service both on my desktop and laptop (using a user agent switcher on my browser). However, I need to do some custom DNS routing and I am running into some issues.
What I want:
1.) When a browser on a device that is tethered to my phone through WiFi Tether Router requests a website then the DNS should run through the default DNS I specify (either Google's 8.8.8.8/8.8.4.4 or OpenDNS or my mobile provider's DNS servers) and load the website from the public internet.
2.) When a browser on a tethered device requests my-example-domain.com or my-other-domain.com I want the DNS to resolve to an IP of my choosing. In this case (for now, but I want to be able to change it), I want it to resolve to the IP address of my phone that is providing the tethering. The local IP address of the phone is is 192.168.11.254, which is the Default Gateway address when running Wifi Tether Router. I have a web server running on the phone on port 8080 and I want it to receive the requests for my two domain names
I want nearly all traffic from tethered devices to resolve through public DNS servers, but for those two specific domains I want the DNS to be handled by the DNS server running on the phone. I want those specific requests to resolve to the same phone that is providing the tethering and to have the web server running on the phone serve the files.
I have most of this working correctly except for one issue. Here are the details.
I am using three devices:
Galaxy Avant to provide tethering "phone"
Windows Laptop "laptop"
Windows Desktop "desktop"
Scenario 1 - Using Google DNS on phone:
In WiFi Tether Router under DHCP Settings I have:
HTML:
IP Address: 192.168.11.0 (0 is disabled and can't be changed)
DNS 1: 8.8.8.8 (google)
DNS 2: 8.8.4.4 (google)
When either of the Windows computers connects via wifi they receive the following:
HTML:
Default Gateway: 192.168.11.254
IP Address: 192.168.11.1XX
The laptop has a dynamic IP and DNS assigned by the DHCP in Wifi Tether Router on the phone.
The desktop has a static IP of 192.168.11.102 with its DNS pointing to the phone at 192.168.11.254 for DNS 1 and 192.168.11.0 for DNS 2 (I know the second one is invalid, but Windows requires two)
Under this scenario both the laptop and the desktop can access live websites through their browsers.
I'm assuming that the DNS is running through Google's 8.8.8.8 since that is the primary DNS for Wifi Tether Router and both computers are getting their DNS from the phone.
Scenario 2 - DNS running on Windows Desktop:
In WiFi Tether Router under DHCP Settings I have:
HTML:
IP Address: 192.168.11.0 (0 is disabled and can't be changed)
DNS 1: 192.168.11.102 (desktop)
DNS 2: 192.168.11.102 (desktop)
Both Windows computers still receive the following:
HTML:
Default Gateway: 192.168.11.254
IP Address: 192.168.11.1XX
Since the DNS 1 and DNS 2 settings for WiFi Tether Router now point to 192.168.11.102 (desktop) instead of 8.8.8.8/8.8.4.4 (Google) the DNS is now handled by the desktop.
The desktop is running Simple DNS Plus which is configured to point my-example-domain.com and my-other-domain.com to the IP address of the phone at 192.168.11.254.
There is a web server running on the phone.
Both computers can still access live websites through their browsers and both computers can access the web server running on the phone by visiting my-example-domain.com:8080 or my-other-domain.com:8080
The only records I have defined in Simple DNS Plus on the desktop are for my two domains, so I'm assuming that the rest of the DNS requests are getting passed back to the phone to be handled by the phone's default DNS servers since WiFi Tether Router no longer knows about Google's DNS (because it is now pointing at the desktop to resolve DNS instead). The DNS settings for the wifi network adapter on the desktop are pointing at the phone's 192.168.11.254 address still (which seems like it should create some sort of loop since the phone and desktop both point at each other, but it doesn't? Maybe someone can clear this part up for me), so even though my-example-domain.com and my-other-domain.com are being redirected by the DNS server on the desktop to the IP of the phone where the web server is listening, every other DNS request must be going back to the phone and resolving there since the phone is the desktop's only source of internet and the live websites actually resolve. The desktop must be either sending the request back to the phone to resolve or using the phone's data, but either way the desktop is forwarding the domains that it is supposed and leaving the rest up to the DNS on the phone somehow. I'd like to have a better idea of how this actually works.
In my head it's doing the following:
Request for my-example-domain.com or my-other-domain.com from laptop:
Checks DNS on WiFi Tether Router on phone > Forwards all DNS to Simple DNS Plus on Desktop > Points and resolves to web server on phone
Request for any other domains from laptop:
Checks DNS on WiFi Tether Router on phone > Forwards all DNS to Simple DNS Plus on Desktop > No record found for host > Returns DNS request to WiFi Tether Router on phone > Resolved by default DNS of phone
Scenario 3 - DNS running on Phone:
I installed the "DNS Server" app from Ice Cold Apps on the phone and created a DNS server instance, but I am not allowed to choose port 53 so I chose to have it assign random port (40747). If I try to set the port for the DNS Server to 53 I receive an error saying "The port you entered is not valid, try another one (this normally happens because Android doesn't allow a server on that port or another app is using the port)."
I created a rule that points my-example-domain.com and my-other-domain.com to the IP address of the phone at 192.168.11.254. The rules are very simple, you can only provide a domain name and an IP address for the DNS Server to route it to, nothing more.
In the DNS Server settings there is a checkbox for "Use a DNS server for requests" which is checked by default with a box attached to it for "DNS Server IP" which is set to 8.8.8.8:53 by default, which is Google's DNS on port 53.
There is another checkbox (that I unchecked) which says "Use a web DNS server for requests" with a box attached to it for "Web DNS server url" that is pre-populated with a PHP url from China
There isn't much documentation for these apps, so I assumed that it was ok just to use the Google servers from the first setting and skip the unfamiliar web DNS server stuff. I'm guessing those settings are supposed determine where the DNS Server app checks for hosts you didn't explicitly define with a rule. For example, if someone types one of my two domains name it should forward, but any other name should be checked with that provided DNS server. I could be totally wrong about this, so some clarification would be nice.
In WiFi Tether Router under DHCP Settings I have:
HTML:
IP Address: 192.168.11.0 (0 is disabled and can't be changed)
DNS 1: 192.168.11.254 (phone)
DNS 2: 127.0.0.1 (phone)
There is no option for port for the DNS so it's checking port 53 on my phone, but the DNS server wasn't allowed to start on 53 so it's listening on 40747 instead. This means I need to forward port 53 to port 40747 so that the DNS requests sent to DNS Server on port 53 by WiFi Tether Router will be answered.
I installed the "Port Forward Ultimate" app from Ice Cold Apps on the phone. There is only one setting, a checkbox which says "Force using internal iptables (advanced)". I left it unchecked initially, but found that the port forwarding server will not start unless that box is checked (and it doesn't matter what ports I'm trying to forward, without that box checked it simply will not start).
I created the following rule in the port forwarding app:
HTML:
Source port: 53
Destination port: 40747
I left the "Forward to external host" box unchecked and the accompanying "Forward to host/IP" box empty.
I started Port Forward Ultimate, DNS Server, and WiFi Tether Router.
Both the desktop and the laptop connect to WiFi Tether Router, but neither of them can access live websites and neither of them resolve my-example-domain.com or my-other-domain.com
I first thought that maybe the port forwarder couldn't bind to 53, so to test I changed my port forwarding settings to:
HTML:
Source port: 53
Destination port: 8080 (the port the web server is running on the phone)
When I visit 192.168.11.254:53 in Internet Explorer 9 from the desktop or laptop it works just fine (Chrome and Firefox won't let you browse websites on port 53, they show show a security error, but IE works). I see the website from the web server that is running on port 8080 on the phone, so port 53 is bound and forwarding to 8080, but when I try to forward 53 to 40747 (the port of the DNS server on the phone) it doesn't work. I've tried the DNS server on various ports (40747, 1029, etc). I made sure the port forwarder set to forward 53 to the port of the DNS server. I also made sure WiFi Tether Router set to use the phone (192.168.11.254) as the DNS, but live websites won't load and the the rules I have in the DNS server app on the phone do not cause my-example-domain.com or my-other-domain.com to resolve to either the phone itself on 192.168.11.254 or to the desktop web server running at 192.168.11.102 (I've tried setting it to forward to both).
I can forward port 53 directly to the web server on the phone or to the web server on the desktop (by checking "forward to external host" and providing the IP of the desktop), but when I set 53 to forward to the DNS server on the phone then the DNS server never does its job, as if it isn't even receiving requests.
When I run nmap on the phone at 192.168.11.254 with DNS and port forwarding enabled on the phone I get:
HTML:
PORT STATE SERVICE VERSION
53/tcp filtered domain
With port forwarding off I get:
HTML:
PORT STATE SERVICE VERSION
53/tcp open domain dnsmasq 2.62
When I run nmap on 40747 (or 1029 or any of the ports I've tried for the DNS server) with DNS running on the phone I get:
HTML:
PORT STATE SERVICE VERSION
1029/tcp filtered ms-lsa
WiFI Tether has no problem handing off the DNS to the Simple DNS Plus running on the desktop, but when it tries to hand the DNS off to DNS Server running on the phone it doesn't resolve.
Perhaps there is some kind of conflict I don't understand, like maybe when the DNS setting in WiFi Tether Router tries to connect to 192.168.11.254 on port 53 and is supposed to get forwarded. I do know that at all times I can access 192.168.11.254:8080 from the desktop as long as the web server is running and I am tethered to my phone.
Lastly, there is a checkbox in the DHCP settings for WiFi Tether Router which says "DNS Redirect" that when checked displays two IP address boxes for DNS 1 and DNS 2 under a header that says "Redirect DNS To". I'm not sure what this is, but it could be important. The only other two options under DHCP are "Use Internal DHCP" and "Use Alternative DHCP Config".
All I want is for most requests from tethered devices to go through standard DNS while the domain names I add host records for in the DNS Server on my phone will resolve to the IP addresses I specify, whether those IP addresses are external or the IP of the phone itself where the web server is running.
I have most of this working, including being able to hand off the DNS from WiFi Tether Router to one of my computers to do the routing, but I want to have it all self-contained on my phone as a standalone setup.
The web server is working, the tethering is working, the tethering handing off the DNS is working, the DNS on the desktop correctly routes the domains to the phone and the rest of the requests to live DNS, and the port forwarding appears to be working when forwarding 53 to my web server, so I'm just kind of stuck.
I've been working on this for 12 hours and I've hit a wall.
It could have something to do with needing to forward both UDP and TCP in the port forwarding, although there's no direct option for that except a box to create custom scripts that modify iptables, which I've tried but had no luck with. Or maybe Wifi Tether Router binds port 53 and is conflicting with the port forwarding / DNS server.
I'm open to any ideas as to why running WiFi Tether Router through the DNS on my phone with port forwarding doesn't work, but running WiFi Tether Router through DNS on my desktop does (especially since the DNS on the desktop correctly points my two domain names back to the phone for the web server to answer and also resolves live websites, both tasks that are receiving and sending requests through the phone); your input will be greatly valued.
The goal of this entire effort has been to create portable and private prototypes of browser-based applications that I've developed for still-to-go-live domain names and be able to run them entirely from my phone on any device that I tether (without modifying the hosts file on the tethered device) so that I can do on-the-fly demos even in areas with spotty data service. In addition, I can load up my SD card with media assets and personal content such as images, audio, and video and have everything available instantly in the web applications when I demo. I can also ensure that the only way to see particular applications I'm developing or access demo data is if you are directly tethered to my device. I can run full database software, application servers, and everything else directly from my phone and make changes to the apps instantly. All I need now is this one little DNS fix and I'm set.
Thanks!

how to change rndis0 ip address 192.168.42.129/24

my android is 7.0 version,usb share to windows network and andriod rndis0 ipaddress is 192.168.42.129.
that can ping now
if I try to use
ifconfig rndis0 192.168.42.121,
then the windows can not ping 192.168.42.121.
I also try to set windows ip address static 192.168.42.x to ping 192.168.42.121,but can not ping,

Categories

Resources