is it possible to scan a LAN for localhosts? - android

I am a technician and travel to customers all the time. At site i need to connect to a localhost webpage located on a server somewhere in the network. I dont always have the IPadress and the premises is big. I wish there was a way to scan the network for localhost. I'm of course connected to wifi.
I have created a tool on my android device that finds the local iPadress and connects to the localhost with the most know ipadress of my customers. But sometimes not all network configuration is standard, so it can be difficult to find the last numbers in the iPadress.
So my question is: is it possible to scan a network (lan) for localhost pages?
Is it a know way or tool to do this with windows or android?

Take a look at the Fing Network Tools Android application. It's great for spidering a LAN to discover connected devices and identify them. Once the discovery is complete you can run a port/service scan for HTTP servers to find your "localhost" site.

Related

Is it possible to access an HTTP server deployed on an Android phone from another device on the same network?

I am using the NanoHttpd library to set up a server. It is currently serving a 'Hello World' HTML page.
It is accessible from the browser of the phone on which it is deployed but not on other phones or laptops on the same WiFi.
For example, http://10.54.92.228:8080 is accessible to the browser of the phone on which the server is deployed. But, is inaccessible to other devices over the network. Is there any way to enable incoming connections ?
I am working on a similar project, I have to host files over WIFI on an android device which is accessible to anyone on the same WIFI network.
The web server is working as I want.
I think the problem is with your IP-Address of the server.
For a WIFI network, the network should be in the range of 192.168.137.XXX.
What you are inputting is the global ip of the device on which your server is.
Check you local ip, and enter it with the port number and it will work.
Ping me if you need any help.

Android: Client-Server using TCP, and discovery of PC/Mac on LAN (WiFi)

I want to create app in client-server model. So I written desktop server and mobile client library. Now I encounter some problem with automatically discover PC/Mac computer in LAN network from Android device.
Possible solutions:
get android device ip address, get subnet mask, use org.apache.commons.net.util.SubnetUtils class to getInfo().getAllAddresses() and scan them all using InetAddress.isReachable(timout=1000ms) This solution works but if we have optimistic subnet mask 255.255.255.0 it must scan 254 addresses and it takes 254 seconds => > 4min. Ok I could use threads, maybe addition of 10 threads and splitting this task to check about 26 ip addresses could make it below <45 seconds. But there also can be subnet mask 255.255.0.0 (less probable but...).
Android don't have arp -a command line tool, but it has something like /proc/net/arp file? I am reading this file and can get some ip addresses in LAN very fast, I can reject IP addresses that don't have real MAC but 00:00:00:00:00:00. I could also find then vendor of this device also using some api, local database?
The problem is that I have read this file has some drawbacks like contains non existent devices (after their disconnection)? and not all devices actually connected? Is it right? So Can I relay on it or not?
Both above solutions enable to find only IP address, what about port number of my server app. Ok I could use fixed port number (but it can be used by some other service and then there will be problem). Maybe trying consecutive addresses from xxxx port number like, xxxx+1, xxxx+2,.... etc. to the moment I find some on which I can correct. So the connection could take reasonable amount of time I suppose.
I have read about NSD or DNS-SD:
https://developer.android.com/training/connect-devices-wirelessly/nsd.html
This seems to enable register some service (In my case my server-side app) and enable it to be discovered in local network by other devices? Is this useable in the case of PC/MacOS server app registering for discovery, and Android App finding this service using NSD?
When I have IP address how can I get name of the device:
i.e. name that is displayed here "Play Internet 4G..." which is my wifi router.
or the name of my computer that is displayed here
I think using NSD (Network Service Discovery) implementing DNS-SD (Service Discovery) and on MacOS (also Windows, iOS) Bonjour
http://developer.apple.com/bonjour
Will be the best way to implement discovery of devices (services offered by client-server local network software) in LAN. You can get also descriptive names like name of the computer or server app running on that computer to show the end user. There is dns-sd command line tool in Terminal on macOS you can test registration of services in network and their later discovery. It works perfectly well and fast. Example screenshot of my Android app discovering service registered in macOS command line tool.
Watch more:
https://developer.apple.com/videos/play/wwdc2011/211/

How can I send http messages from android app( physical device) to my local server without using internet connection?

I have an app that runs in an emulator. The app sends multiple messages to my local server, for manipulating data. While i was using the app in my emulator i was using:
http://10.0.2.2/path
to reach the server. I would like to use a physical device to connect to the server. Does somebody know how to do this. What adress i should use?
Assuming that your devices are on the same Network (connected to the same router) as your computer, you can expose your computer's web server (Apache, presumably?) and then point your app directly at the local network IP address that your computer has (usually something like 192.168.1.x). I have found that the least painless way to do this is to use MAMP or WAMP or LAMP depending on your OS, but of course I have no idea what your specific situation is, so that solution may in fact make things a lot more complicated rather than less.
In any event... your computer is on the network at a specific IP address, so it's just a matter of making sure that it's willing to serve this data on whatever port you are looking for it on. If you provide more specification as to your circumstances, we can give a more detailed answer.

Testing the server side code before deploying

I need to send an image file from the mobile to the server(where the server will save it to the hard disk). I have wrote both the android mobile part and the server side. I need to test the code before deploying to the server. Will the code work if I connect the mobile to the WI-Fi network through which I can have a LAN connection to the system? Is there any way I can test the code with out using a WI-Fi connection(ie Connecting phone to the system via the usb cable and then forming a LAN or something)? Please voice your valuable opinion in these stuff.
When I was testing my server-side I didn't find any other way rather than connecting via wifi, this way it was working just fine (in your code you need to use ipv4, not localhost, just as reminder). I'm not good with network stuff, but I don't think it's possible using usb to create some kind of LAN.
Have u tried from emulator? How to connect to my http://localhost web server from Android Emulator in Eclipse

How to start a local network connection programmatically via Wi-Fi hotspot on Android?

I want to start a local network connection using the built-in Wi-Fi hotspot on Android devices.
Is there a way to accomplish it?
And how to communicate between two devices?
EDIT:
I want to do it programmatically. Then I can transfer my own data between devices.
I haven't done this before, so my answer is all theoretical.
I think what you need to do is declare one device the server and start its hotspot manually with a known name.
Start / stop built-in Wi-Fi / USB tethering from code? (According to this question, you can't start hotspot programatically).
Once you have the hotspot set up, you start up the server app and wait for incoming connections. The server app can show you the ip address or hostname.
On the clients, you can do a simple check and see if the hotspot name is around and automatically connect to it if you find it. See this link for connecting to a network:
Using WifiManager to connect to a network
As for your second question, how to communicate - you need to establish a connection between the devices. For this, you need the ip address of the server. The simplest thing to do would be to show the ip address on the server UI and then manually enter it on the clients and press connect. It would then establish a connection to the server on a known port and you can send messages between client and server.
For reference, I found NanoHttpd, which is a webserver for Android. It uses ServerSocket to listen for incoming connections.
Possible answers:
Before ICS and non rooted devices
There is no way you can connect to a device over wifi. There is no API to do. Bluetooth is your best option or user interaction.
Before ICS and rooted devices
I am not sure if someone hacked the code, but when I tried to do an automatic connection to a wifi spot I noticed:
The api is hidden inside the SDK.
The method that does the connection checks the thread who ask for it. If it's not the os thread, it throws an exception.
Using ICS
With ICS there is a new way to connect devices through wifi called Wi-Fi Direct.
Here is a link with some demos.
If you are going to develop your own application for each and every individual terminals(devices) then i think for you socket programming will do the trick .
Yes , android supports socket programming in the same was as java socket programming .
1st google java socket programming tutorials and then you can using the same knowledge in android .
Also do remember to include the uses internet permission in the manifest , actually thats something which ate my brains for a long time :)
You mean communication between wifi enabled devices without any server like p2p? if so its wifi direct which is supported in ICS check this out http://developer.android.com/reference/android/net/wifi/p2p/package-summary.html
Before ICS there is no standard android API for wifi direct, though Galaxy S2 has wifi direct it uses proprietary API's which 3rd party devs can't use.
i dont know programmically create wify LAN,but you can create wify LAN manually,then you can do java tcp/udp program as said by brianestey
"As for your second question, how to communicate - you need to establish a connection between the devices. For this, you need the ip address of the server. The simplest thing to do would be to show the ip address on the server UI and then manually enter it on the clients and press connect. It would then establish a connection to the server on a known port and you can send messages between client and server."
for manual connection follow the steps
take settings/wireless&networks/portable wi-fi hotspot settings from any one of the phone
create new hotspot and turn on wi-fi portable hotspot from there
connect all other device to that hotspot including your pc
you will get ip of each device programmically (includig pc,but i dont know)

Categories

Resources