How can I find out whether I can be seen from outside in my iPhone App? - iphone

Using services like http://canyouseeme.org/ one can find out whether a particular port is open and his (public) IP is reachable from outside world.
Assuming I have my (expected) public IP and port, is there some easier or more reliable way to check my reachability than e.g. calling canyouseeme.org ?

iPhone's don't have a public IP (as far as I know).
Using 3G coverage you get allocated a local IP on your networks WAN.
Using WiFi you get allocated a local IP from your router.
Therefore I doubt you'll ever be able to truly identify your iPhone using an IP you think is associated with it (but probably isn't)

Related

How do I get the public IP address when starting a GSM modem in server mode?

I have a SIM800C GSM module that I want to use to make a server. I am really confused about knowing the public IP address. In order to make people to connect to any server is that they need the correct public IP address and the correct port, and of course the correct protocol (TCP, HTTP and so on..).
There is already a command to get the local IP address (AT+CIFSR); in case I make a server and I want to let my friends connect to it, I need the public IP address. How do I get it?
I searched on the internet but found nothing.
AT+CIFSR (as well as the standard command AT+CGPADDR) returns your IP as soon as you activate the PDP context. Unfortunately, if it is public or not depends on your operator. In fact, due to the need to face the IPv4 address exhaustion they often perform a Network Address Translation (NAT) that will actually provide a local IP to your device.
As a consequence, your device won't be reachable for communications that are not device-initiated, and you won't able to create a public server at all.
So, that's not a public IP opposed to a local IP: there's just the IP you obtain from the network. If doesn't perform NAT, then the IP you obtain with AT+CIFSR will be the public one.
Design work-around
Usually the NATted IP limitation is faced with a design trick
A wake-up SMS is sent to the device hosting the server. The SMS can either be a basic one (just text containing data relevant to the application) or a special SMS type (Wap Push notifications).
As soon it receives the SMS, the device starts the server and sends some data to the remote peer
This will result in a device initiated communication, so from the network side the NAT will be opened and the device will be temporarily public.
After a certain inactivity time (operator dependent) the NAT will be closed again
"Commercial" solution
If the design solution is not feasible, there's another option involving the purchase of special (and more expensive...) SIMs specific for M2M and IOT applications:
SIMs which will always obtain a public IP
SIMs which will always obtain a public fixed IP

Is there an ethernet link layer protocol to get remote IPv4 settings?

Given one or more embedded devices of the same type with some unknown IPv4 addresses or maybe no IPv4 addresses set at all: is there any Ethernet based network protocol to ”find“ those devices in the local net (LAN) from remote (PC) and get their IPv4 settings?
What not works for me:
ARP: IP address must be known or only finds device I communicated with before (or ugly ARP floods …)
LLDP: point to point only (?), so I would only see the switch between device and me. Also, just announces, no response on request (because there are no requests). Further: asking the switch (which supports LLDP) through SNMP is no option when using dumb switches
IP based protocols: I played with UDP and broadcasts (both as request and response), but that does not work reliably if device and me are on different subnets, and it does not work at all if device has no IPv4 set.
DHCP: does not work in networks without DHCP server, maybe no DHCP client on the embedded device
I assume others had the same problem before, take manufactures of network equipment like access points which should be configured remotely, powerline adapters, switches … all those where the vendor gives you some proprietary tool, the device shows up like magic in a list and you can assign some IPv4 then.
Of course the device must have some daemon listening and responding to certain requests, but what would be a standard protocol for such a task? Or do I have to make up some new protocol for that? May some of the above mentioned is possible, but I overlooked something?
Ethernet only provides a layer 2 connection, so anything Ethernet-based can't ever work across a router (ARP, LLDP - LLDP doesn't even cross a decent switch as it's link layer only).
Depending on the network, routed multicasts or directed broadcasts could work - normally they don't. All vendor tools I've seen just use (Ethernet) broadcasts and don't work across routers.
Most often, simple DNS is used for this purpose - the device registers with the DNS server or is preregistered and you just resolve the name.
Edit: without the router problem, the simplest way is to use a UDP broadcast to some unused port. With DHCP unavailable, the device could fall back to zeroconf (169.254.0.0/16) and broadcast from there.
Without IP, you'd need a "raw" Ethernet socket and use an Ethertype that doesn't interfere with normal network operations.

iphone app can't see internal network

I'm working on an Enterprise app that communicates with our company servers. I have full two-way communication between the phone and the server through 3G/4G, and it works from my home wifi, but using the wifi at the office where it is connected to the company network the app doesn't see the server that way.
The app is set to look for our external IP address, and the port is open to the server. But I guess the external IP address is not 'visible' from within the network. When I plug in the internal IP address of the server, it goes through just fine.
For the vast number of our users, that would not be a problem. Most of our users (employees) work in the field or in other offices. But for users inside our network, this arrangement is useless unless the user turned off his wifi. But that's not a professional way to do it.
I need to know if there's a way for my app to either use 3G/4G exclusively, or to discover the SSID of the wifi and decide which IP address to use. I'm guessing that the answers to both of these will be, "you can't do that," But I thought I'd ask anyway.
Thanks!
You could have it attempt the internal IP, and fall back to the external IP if it can't connect. A better solution might be to have an internal DNS server that serves the internal IP to in-network devices, though.
Well, I discovered this code is exactly what I need. It gives me the SSID in string form, and I can compare the SSID string with a string of our wifi's SSID, and if it matches then the app uses the internal IP address. And if it doesn't match, it will connect to the external IP address. So far it works perfectly!
Followup: ceejayoz, I don't know if your second suggestion is the same as what our IT guy did, but he created a domain name that will resolve to the server whether it's internal or external. That seems to be the best way to go. So even though I had a workable answer, the URL works better with less code.

Possible to send data between two iOS devices?

I've read tons of questions about this all over the web, and can't seem to find a solid answer. If I have an iPhone that's running on cellular data and another iOS device on wifi (in two separate locations), is it possible for them to send data to each other directly without sending it first to a web server, then retrieving it? Are the only options sending and receiving from a server/Apple's iCloud? What if I knew the devices' ip addresses? Note that the iPhone has WiFi disabled.
I'm not looking to put this in the app store, it is for personal use. I know NSNotificationCenter isn't an option.
Using the gamekit framework you can send data between two iOS devices. It is easy to implement. Other than that I don't think there is any other way to send data between two iOS devices.
Actually, it IS possible. You may want to google for something called "UDP hole punching" or "TCP hole punching".
The main approach in short: Assuming you got something like a relay server, that is some server in the internet that is publicly addressable from every private LAN that is connected to the www. No you have your two clients A and B in (different) private LANs, with some Network address translation (NAT) going on, that want to establish a peer to peer connection.
First of all both will tell the server their IP address and the port they have in their own LAN. In the UDP or TCP packet, the server will find the public address and port of the device (or the NAT (router)). So the server knows the private and the public IP address as well as the ports.
If now A wants to communicate with B, it asks the server for help. The server will send a message to B that A wants to communicate with her telling her A's public and private IP and port. A gets back B's public and private information and port.
Now here is where the magic happens. Both clients now send packets out to establish a connection simultaneously to the private and public addresses of the other party and thus punching a whole in their NATs such that incoming connections will not be blocked. Even if one party's connection establishing packets will arrive before this whole is created, the other's packets will get through to such that a connection can be created.
Beware of some NATs that scan the data for IP addresses and translate them as well, but if you encrypt your data or change the appearance of the address (complement, ...) you will be fine.
Now the master question, how can the server communicate with one of the clients without an active connection. Well in this case you can use "connection reversal" and apple's "push notifications". Use the "push notifications" (pn) to tell a client behind a NAT that there is something of interest going on and that it should contact the server. Once it has done that the connection is active and can be used in the previous described fashion.
I hope this helps some people that get to this problem although the post is quite old!
You can only use direct IP address communications if the IP address are publicly reachable IP addresses accessible over the internet, and they are static (enough) so that they are not changing on you regularly as devices get assigned to addresses dynamically. In many (most) cases, that won't be true because your devices will be assigned their IP address dynamically and those addresses are frequently going to be self-assigned IP addresses that aren't publicly addressable.
As others have commented, using Apple-provided mechanisms like iCloud are probably the easiest options. If that's not something you'd like to entertain, there are probably ways to make use of a dynamic DNS service like DynDNS to manage the actual IP addresses of your devices. With something like that you might be able to use a direct IP connection between devices based on a named DNS lookup. You'd probably have to jump through some hoops to make that happen though and I'm not sure you'd want to go to that extent.
I think that Bluetooth would be a good option for you

Coordinating peer-to-peer messages using multicast, how to get receiving IP?

I have been working on a local LAN service which uses a multicast port to coordinate several machines. Each machine listens on the multicast port for instructions, and when a certain instruction is received, will send messages directly to other machines.
In other words the multicast port is used to coordinate peer-to-peer UDP messaging.
In practice this works quite well but there is a lingering issue related to correctly setting up these peer-to-peer transmissions. Basically, each machine needs to announce on the multicast port its own IP address, so that other machines know where to send messages when they wish to start a P2P transmission.
I realize that in general the idea of identifying the local IP is not necessarily sensible, but I don't see any other way-- the local receiving IP must be announced one way or another. At least I am not working on the internet, so in general I won't need to worry about NATs, just need to identify the local LAN IP. (No more than 1 hop for the multicast packets is allowed.)
I wanted to, if possible, determine the IP passively, i.e., without sending any messages.
I have been using code that calls getifaddrs(), which returns a linked list of NICs on the machine, and I scan this list for non-zero IP addresses and choose the first one.
In general this has worked okay, but we have had issues where for example a machine with both a wired and wifi connection are active, it will identify the wrong one, and the only work-around we found was to turn off the wifi.
Now, I imagine that a more reliable solution would be to send a message to the multicast telling other machines to report back with the source address of the message; that might allow to identify which IP is actually visible to the other machines on the net. Alternatively maybe even just looking at the multicast loopback message would work.
What do you think, are there any passive solutions to identify which address to use? If not, what's the best active solution?
I'm using POSIX socket API from C. Must work on Linux, OS X, Windows. (For Windows I have been using GetAdapterAddresses().)
Your question about how to get the address so you can advertise it right is looking at it from the wrong side. It's a losing proposition to try to guess what your address is. Better for the other side to detect it itself.
When a listening machine receives a message, it is probably doing do using recvfrom(2). The fifth argument is a buffer into which the kernel will store the address of the peer, if the underlying protocol offers it. Since you are using IP/UDP, the buffer should get filled in with a sockaddr_in showing the IP address of the sender.
I'd use the address on the interface I use to send the announcement multicast message -- on the wired interface announce the wired address and on the wireless interface announce the wireless address.
When all the receivers live on the wired side, they will never see the message on the wireless network.
When there is a bridge between the wired and the wireless network, add a second step in discovery for round-trip time estimation, and include a unique host ID in the announcement packet, so multiple routes to the same host can be detected and the best one chosen.
Also, it may be a good idea to add a configuration option to limit the service to certain interfaces.