I notice that some of the better network discovery apps like Fing for iOS and iNet for Mac are able to discover the device name of iOS devices and Mac devices even when they are not advertising Bonjour services such as iTunes Wi-Fi Sync. How is this done? I am aware of how to do a reverse mDNS query https://serverfault.com/questions/143184/how-do-i-get-the-machine-name-from-an-ip-via-multicast-dns. But while a reverse mDNS lookup (at least as accomplished by the dig command dig -x the.ip #224.0.0.251 -p 5353) will work against a Mac that is not otherwise broadcasting any Bonjour services, it doesn't work unless Wi-Fi Sync is running or some other Bonjour service on an iOS device. I am not sure how to get the name otherwise but these apps reliably get it. I used Wireshark while iNet was discovering and I only see ICMP and NetBios queries all which return 0 answers.
Also note that I have the IP address of the device already by doing a broadcast ping and then parsing the ARP table. I want to discover which of the devices discovered in this way are iOS devices by getting their device name and looking for the string "iPhone" or "iPad".
Also note that the iNet app website provides the following about how they do reverse IP lookups. I take this to mean they do a reverse DNS lookup and a reverse mDNS lookup for every IP.
Reverse IP lookups (hostnames) are performed as unicast and multicast queries for every IP found. -http://www.bananaglue.de/inet/index_e.php
Have you tried the dns-sd command line tool?
If you type dns-sd -B _services._dns-sd._udp to get all available services, you'll see there's a _whats-my-name service available.
$ dns-sd -B _services._dns-sd._udp
Browsing for _services._dns-sd._udp
DATE: ---Tue 16 Dec 2014---
14:38:30.746 ...STARTING...
Timestamp A/R Flags if Domain Service Type Instance Name
14:38:30.747 Add 3 5 . _tcp.local. _nfs
14:38:30.747 Add 3 5 . _tcp.local. _afpovertcp
14:38:30.747 Add 3 5 . _tcp.local. _smb
14:38:30.747 Add 2 0 . _tcp.local. _whats-my-name
14:38:31.330 Add 3 10 . _tcp.local. _nfs
14:38:31.330 Add 3 10 . _tcp.local. _afpovertcp
14:38:31.330 Add 2 10 . _tcp.local. _smb
after that we can query for this service which outputs the following:
$ dns-sd -B _whats-my-name._tcp
Browsing for _whats-my-name._tcp
DATE: ---Tue 16 Dec 2014---
14:40:20.738 ...STARTING...
Timestamp A/R Flags if Domain Service Type Instance Name
14:40:20.742 Add 2 0 local. _whats-my-name._tcp. Blub MacBook Pro
The Instance Name is the interesting part here. I assume the _whats-my-name service is available on every computer running bonjour. Maybe you can hunt down the sent queries and reconstruct it with basic bash tools if you can't access dns-sd in every case. More over you should not use dns-sd in your script. Instead you should use a specific implementation of the protocol for your programming language.
Note: Be aware that the name of the device may not be reliable to detect which device you are communicating with
Hope that helps.
Related
I have a Bonjour _http._tcp. service published on iPhone. With the iPhone Wifi Off; running the following dns-sd command on MacBook's terminal:
dns-sd -B _services._dns-sd._udp
then connect the iPhone to MacBook with USB Lighting cable, dns-sd would discover the following iPhone service:
Timestamp A/R Flags if Domain Service Type Instance Name
19:22:45.126 Add 3 5 . _tcp.local. _http
disconnect the USB Lighting cable from the MacBook would show:
Timestamp A/R Flags if Domain Service Type Instance Name
19:22:45.126 Add 3 5 . _tcp.local. _http
19:23:53.924 Rmv 1 5 . _tcp.local. _http
However, repeating the above steps (running dns-sd, connect and disconnect USB Lighting to PC) on Windows 10 PC, dns-sd did not discover the service.
With the iPhone Wifi On, dns-sd on PC would discover the iPhone service:
Timestamp A/R Flags if Domain Service Type Instance Name
19:32:36.238 Add 2 13 . _tcp.local. _http
when the iPhone Wifi Off, dns-sd on PC would show:
Timestamp A/R Flags if Domain Service Type Instance Name
19:32:36.238 Add 2 13 . _tcp.local. _http
19:33:38.471 Rmv 0 13 . _tcp.local. _http
I had Bonjour SDK v333.10 installed from https://developer.apple.com/download/more/?=Bonjour%20SDK%20for%20Windows; and iTunes is working fine (can show the iPhone) on the PC too.
Why dns-sd (Bonjour/ZeroConf) on PC did not discover the iPhone service via USB?
Many thanks.
Bounjour communication is Socket base. When the iPhone is connected to the MacBook via USB cable, MacBook assigns a private IP address (169.254.x.x) to the iPhone.
Using Discovery - DNS-SD Browser on MacBook, when the iPhone's wifi is Off, Discovery shows the discovered Bonjour service via USB, with the private IP address:
When the iPhone's wifi is On, Discovery will show the discovered Bonjour service with two IP addresses (one wifi's, and one USB's):
Therefore, dns-sd on MacBook was able to discover the service on iPhone without wifi.
I have been trying to figure out the exact issue. I have two UDP base services running on my local Wifi network. My Bojour discovery app NOT able to discover one of the service(Real) 3 out of 10 times. Where as it discover the other service(Simulation) 10 out of 10 times.
When i run this command
dns-sd -B _coap._udp.
on terminal, its showing me both of the services. Then why my app failing to discover the Real service some of the times.
I have the following case:
Two applications (mine and 3rd party) on iOS need to communicate over TCP/IP
I can change the code of my app, but not the 3rd party app
The protocol can't be changed (because I can't change the 3rd party app).
In my app, I want to make sure that I talk to the correct app.
I know how I can get peer port with geetpeername
What I am looking for is a way to figure out the pid of the process which uses this port.
I found similar question: How do you determine the PID of a peer TCP connection on the same iOS device?
However, in his case, both ports are in the same app.
Disclaimer: I am fine with private API. It won't be sent to AppStore. However, I am looking for a solution for non a jailbroken phone.
Update 1
I said that I need PID, because there are known ways of getting association between PID and application bundle id (using sysctl).
Generally speaking, I don't care about PID per se. My concern is figure out what is the application on other side of the socket.
I don't have a solution for this, but if I was going to try to do it, I would proceed in the following way:
On a UNIX system, you can use the lsof command to determine which processes have which files open. This includes sockets, and lsof allows you to determine the pid of a process using a given port. For example, use
lsof -n -P -i :443
if you're trying to determine which process is using port 443 (HTTPS), which might yield (on OS X):
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
firefox 81615 myname 112u IPv4 0xffffff8017379a40 0t0 TCP 192.168.2.7:52521->74.125.28.103:443 (CLOSE_WAIT)
The open source version of lsof for Darwin, I believe, can be found here. So you might try starting with main.c, and using those command line arguments, navigate through the code until you find the system calls that are used.
It's certainly possible that the calls needed will not work when run in a process with user mobile privileges. But, maybe not? If there's a security check inside the lsof source itself, then you can certainly remove that, if you copy and paste the source yourself.
Anyway, it might be worth a try, if no one offers another answer.
Note: lsof is available for jailbroken phones, and I just tried running the current versions available from Cydia. They did not work for me, on 5.1.1 or 6.1.2. Not sure why. I assume that if they were on the repository, though, at some point, someone was able to port lsof to iOS.
I'm brand new to RoR and have pretty much 0 experience with it. I have been handed down somebody else's project and I need to find a way to host the application, so people can just access it locally. The application is a spider script/walker script/web scraper whatever you call it. Basically it connects to a website, logs in, retrieves certain data each day and maps it with the previous data. While on the local machine, you use it, go to localhost:3000, and you get the webpage the previous person designed. I was just wondering how I could get that page to be public for the people on our local network, so they could connect to some arbitrary IP and see the same page (it updates daily)?
What I tried doing is making the folder containing the application public to the network, but in order to use it, I would have to make everybody on the network allowed to write to it and each person would have to install RoR to use it. I want to avoid that since it doesn't seem logical, nor is it what I'm trying to do.
Looking at the code, I can reverse engineer and understand what it does, but when it comes to hosting web apps locally or something of that sort, I have never done this before. Please help!
Thanks in advance!
**EDIT
-This is all being done on a Windows 7 machine.
Since you're on Windows, open up a command line and run ipconfig to find out your local IP. It will be listed under 'IP Address'.
Tell people in your LAN to access http://192.168.x.x:3000 replacing 192.168.x.x by your IP address from step 1.
EDIT: One major thing that I missed, you are windows. On windows u could use thin and put it behind a load balancer. Although i would suggest hosting it on a UNIX machine :)
Although Running it in webrick(webrick is the application server for development i.e when u run rails s) will let other users access the website NEVER do the same for a production application. If you want to run this application in production, u need more powerful application servers like passenger. I would suggest you use it with Apache or Nginx instead of stand alone passenger. Once all this is setup others can use your application by entering the IP(xx.xx.xx.xx) also u can ask your system admin to setup a local DNS so your users need not remember the IP address always.
Description:
While starting Rails Server, we can also setup some options to configure the IP address and also the port number of the site under development environment to host the website in local network. So if we want to change the IP from http://127.0.0.1:3000 to http://192.168.x.x:port (x= 0 to 255 any one number), we can set that in Rails server command! But for this, we will need to find out our current IP address at our current network which will help us to serve the website in local network.
So at first step:
We will open our terminal on our PC. For Android user, we need to open Termux app. Then simply type ifconfig to get the IP address of our device in the current network. We will get an output like this one (Here I'm using Android device for development. So output might be something different than this one on your PC terminal but the process is same):
$ ifconfig
Warning: cannot open /proc/net/dev (Permission denied). Limited output.
lo: flags=XX<UP,LOOPBACK,RUNNING> mtu XXXXX
inet 127.0.0.1 netmask 255.XXX.XXX.XXX
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)
wlan0: flags=XXXX<UP,BROADCAST,RUNNING,MULTICAST> mtu XXXX
inet 192.168.1.103 netmask 255.XXX.XXX.XXX broadcast 192.168.1.255
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)
X= some numbers with our device credentials which is dummied with this variable
If you are using a WiFi router then we will need the wlan0 part to get our device IP. Under wlan0 section there is a subsection of inet showing our current IP! YUP, we need that IP address 192.168.1.103! This might be different for your device and network. This is the key of this mission! Now we're going to the second important step.
So the Second Step is:
That required input command to configure the IP address.
rails s -b 192.168.1.103 -p 8080
Here:
rails s for rails server
-b 192.168.1.103 for bidding the IP address for customisation from the default IP http://127.0.0.1 which is our localhost address.
-p 8080 for port setup. This part is optional. Default port is 3000.
This is the process of changing the localhost IP (http://127.0.0.1) to local network IP which will be available for other device of the same network user.
Now our rails app is available in our local network! Other users in the same network will also be able to visit the website while the server command is running. And the link will be http://192.168.1.103:8080 if you also configure the port number. Otherwise if you have used the command rails s -b 192.168.1.103 without port configuration the link will be: http://192.168.1.103:3000
Again: 192.168.1.103 was for my case, your IP address will be different for your device. That will be needed to use for your server and link address.
I have a app / site that i am running on my local imac and i want to test it on my ipad browser.
Can connect to my imac localhost rails app throught the wifi with my ipad ? If so how!! ?
My app is a multi tenant app that uses subdomains and so i use the hosts file on my my to point for example achme.mycompany.dev to localhost.
How do i do this on the ipad to goto achme.mycompany.dev in the browser and it runs the local app on my imac ?
Hope this all makes sense! Please help.
best regards
Rick
I'm providing an update for anyone who's using Rails 4, has followed the steps in the accepted answer, and still can't connect to the app via development_machine_ip:3000. The reason being that somewhere around version 4, Rails changed the default binding address from 0.0.0.0 to only localhost. By default this allows you to only access the Rails app via localhost:3000 or 127.0.0.1:3000 - which is fine in most cases.
Now if you'd like to access the app from a different device on your network, you can use the -b option when starting the server and specify a binding address of 0.0.0.0
rails s -b 0.0.0.0
This will bind on ALL interfaces including localhost and the IP assigned by your network. You should now be able to access the app via development_machine_ip:3000.
I am hoping that your macbook and iPad are on same network. Now go to "Open network preference". Check screenshot.
You will see an ip.
then from ipad open: your_ip:3000
I use proxylocal ngrok for this:
$ ngrok http 3000
ngrok by #inconshreveable (Ctrl+C to quit)
Session Status online
Account Sergio (Plan: Free)
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://be278635.ngrok.io -> localhost:3000
Forwarding https://be278635.ngrok.io -> localhost:3000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Now you can open http://be278635.ngrok.io from your ipad without worrying about your machine's ip address.
If the subdomain is just going to 127.0.0.1:3000 (or whatever) you should be able to access it the same way by going to your machine's local IP address with the same supplied port number. I look at my rails app on my phone all the time.
If you have virtual hosts or something set up, it's probably going to be more complicated than that.
For this, you would either need to jailbreak your iPad to edit the /etc/hosts file, or add a DNS entry in your router (assuming your router is your DNS server).
One of those two sounds like the easiest.