How to find the router IP address in Objective-C? - ios

I need to find the Wi-Fi's router address from my iOS app. I searched the web for a solution but nothing seems to do it. I need something that is not using private APIs an is not against Apple policies.
I have tried solutions found in the following articles and none of them actually give me the router IP address.
How can I determine the default gateway on iPhone?
Fetching IP address of router to which iPhone is connected
Objective-C : How to fetch the router address?
How to get the WIFI gateway address on the iPhone?
There also could be a way to "calculate" the IP from the mask and device IP (or maybe my TCP/IP course is waaaaay to far back in time)...
Thanks!

I have found a solution and tested it successfully. It was taken from this repo https://github.com/SiteView/GenieForiOS, I extracted only the code I needed for my getRouterIPAddress function.
Disclaimer: I'm not an Objective-C developer so the following code might have a ton of issues. Please feel free to correct me.
I have also made it into a Cordova plugin and included a demo project in the repo. It does what I need. I have also added an Android version, which is only 3 lines long. :)
https://github.com/vallieres/cordova-plugin-get-router-ip-address

Related

ddns and port forwarding on a huawei hg633

Has anybody succedeed in creating a web server at home using a huawei hg633 router ?
I started by using the no-ip service and didn't get very far, as stated in this document this router is not compatible with no-ip.
So I tried using duckdns, following the instructions in the same document but that didn't work either. I also read in this relatively old post that dynamic dns is broken on those routers. In fact when I save my ddns settings, the password looks truncated.
Any port forwarding I set on my router doesn't seem to work, but that's probably related with the problems above (?)
Anything else I could try here ?
Thanks a lot !
For the record, my web server works, I can access it from within my network.

How to connect to localhost using external IP address?

I've searched in general, and looked at suggested responses here, so I hope this isn't immediately marked as a duplicate. So here goes.
I'm building a simple web app with an Angular server using port 3000 on my desktop. I've been testing it with the standard "localhost:3000" URL. I then wanted to make it accessible to others outside my home for testing and review. So I did the expected port forwarding in my router of port 3000 to my local machine at 10.0.0.90. I then constructed a link using my external IP (router's "WAN IP") like "[wan ip]:3000". And this has worked as expected, enabling external access as well as internal access. The only thing funny at the time was having to add "--host 0.0.0.0" to the server invocation.
But here's the problem. My original setup, where everything worked, was a Comcast modem with my router (TP-Link) hanging off of it. Recently, I switched to their Xfinity Gateway combo modem/router (Arris TG1682G). Now, I can't get to the server using the [wan ip]:3000 URL. I can't even ping that URL, they all time out. So, while on the phone with Comcast tech support, and not being able to determine why I had this problem (even after upgrading router firmware and rebooting it), I asked him to try [wan ip]:3000, and it worked! It also doesn't work from any other machines on my local network. But, when I changed my laptop wireless connection from my house Xfinity router to an external one (one of the many "xfinitywifi"s seen in a list of networks, besides numerous neighbors), it again worked! Poking around in Xfinity router admin pages, I didn't see anything that sounded like it was involved with this.
So, any idea what's going on, and how to fix? Thanks for any ideas or guidance.
OK, I think I see what's going on. A colleague mentioned that for this to work, the router needs to support "NAT reflection/loopback". Looking at every setup page on this router, I don't see anything that sounds like that. Further searching shows a page where they state that this router does not support it. Oh well.

How to block IOS devices from accessing certain DNS links

I'm new to networking so please tell me if this isn't allowed, I'm also not to sure how to even ask this question, or if I'm even asking the right question.
Ok, I want to create a .mobileconfig file that will connect on demand to my server, and block a few ad DNS names so all the traffic on my iPhones will be processed through a "DNS blocker" on a linux Ubuntu server, yet I can't find any information on how to do this. I don't know how to search for it as everything I search fails to be what I'm looking for. I have the mobile configuration file ready to go, but I can not figure out how to make the phone send it's traffic through a file that says block "apple.com" for example.
I hope this makes sense, sorry for the noob post, I'm just trying to learn and I can't find help.
Edit: need help on the software side of routing all traffic through DNS blocker Ubuntu Linux vps, have ssh root access

Accessing SimpleHTTPServer on iPhone

I'm developing with WebVR and I'm serving my HTML using the SimpleHTTPServer on my Mac. I want to figure out a way to access this website on my iPhone so I can see what I have created with my Google Cardboard.
I looked through a bunch of stack questions and none of them talked specifically about accessing a local website that is being served via SimpleHTTPServer
I tried getting my ip address and then concatenating the port
Ex. xxx.xx.xx.x : 8000
But it didn't work :( Also, both my phone and computer are on the same network too
Says This site can't be reached. IP_ADDRESS took not long to respond
The way I tried is the correct way. I was using school wifi so I'm assuming they're configured in a way that we aren't able to do that. Once I got home and tried on my local connection, it worked like a charm!

How do I make localhost:3000 available world-wide with my IP adress?

I have a Ruby on Rails application running on localhost:3000. I would like to make it available world-wide, using x.x.x.x:3000 (my IP address).
I'm on Windows XP SP3.
Disable your firewall(s)
Ensure you have port forwarding for your computer enabled in your router (if present)
Thats all! ;)
The key is to run it on the internet facing network adaptor, which might already be doing. You then need to to set up port forwarding on your ADSL or cable modem, if you are behind one (or a similar NAT device). Finally, get a friend to attempt to connect to you.
You might want to use a DNS service to alias your IP address, so people don't have to type it in by hand.
If you specifically need "localhost:3000", then go for #Joe answer, but if you do not care about the URL, you can use https://ngrok.com/.
Simply download it, then run ngrok localhost:3000 in terminal.
You would probably want to ensure that you have a static IP address to start with. You can apply to your ISP for one of these.
You then want to ensure that you have adequate security in place...there are tons of books etc about hardening your server.
If you have a static IP address, you'll need to turn off your firewall and you should be able to reach your machine. (Turning off your firewall isn't really a good idea, but that's a different question.)
If you have a dynamic IP address (you probably do if you're not sure), you need to look into something called "Dynamic DNS", as this will allow our computer to have a constant name, even if the IP address changes. Note that with all the technologies at play these days, your IP address locally is usually not the same one you see publicly. This can be a bit confusing if you're not sure what's going on.
All that being said, most people would opt for some sort of external hosting. This is much better from a security standpoint. Look at heroku for rails hosting. Their free option may be exactly what you need.
If you are running Apache on Windows, there is a button in the Apache tray icon. I can not recall the name but is something like ''go live''. And of course you have to set up the firewall or port forwarding on your router.
You answered your own question. IP addresses are unique over the internet. Just type in the x.x.x.x:3000 and you're there. If you want a human-readable address like yahoo.com, look into dyndns.com or other free domain-name services.

Resources