24
2
I'm surprised this hasn't come up in a challenge yet.
Output the IP address of the machine you're running on. You are required to output both the local and external IP addresses.
Local IP address, ie along the default format of 192.168.x.x
Public IP address can be verified by using google https://www.google.co.uk/search?source=hp&q=whats+my+ip
Output can be in any format. IPv4 or IPv6 or any mix of each is allowed, however they must be the only output. Code can be a full program or a function.
code-golf rules apply so shortest code wins.
Standard Loopholes are forbidden.
EDIT: As per @Peter Taylor's comment, in the case where multiple of either type of address are present, you can choose to either output the first one, or as many as you can access. So long as at least one local and one public are present.
3I think the
0/1
thing adds in unnecessary fluff to the challenge. – Mr. Xcoder – 2017-08-18T09:48:38.190otherwise i thought it'd be too simple... – MysticVagabond – 2017-08-18T09:50:50.573
3
I agree there isn't much interest left in golfing an
– Aaron – 2017-08-18T09:51:13.357if(x){X}else{Y}
, might as well ask to output both informations without input. As always, using the sandbox is advised.1@Xynos It's not recommended to add fluff just to make the challenge harder. The difficulty of a challenge should come from the challenge itself, e.g. the 0/1 format isn't necessary and it really doesn't give a lot of golfing opportunities. – Erik the Outgolfer – 2017-08-18T09:52:51.380
I'll change the challenge to output both as per @Aarons suggestion then :) – MysticVagabond – 2017-08-18T09:53:40.717
1What is any format? Can the output contain garbage (like HTML tags etc.)? Can I output one in IPv6 and the other IPv4? – ბიმო – 2017-08-18T10:13:55.737
Ill accept one in either format v4 or v6 but other garbage is not allowed – MysticVagabond – 2017-08-18T10:17:43.207
5This is underspecified. In particular, it doesn't clearly address cases where there are multiple local IP addresses and/or multiple public IP addresses. Furthermore, there's no reliable way of telling whether I have multiple public IP addresses, and if so what they are. – Peter Taylor – 2017-08-18T11:08:58.487
5What if the host doesn't have any RFC 1918 addresses? It looks like there's no reliable answer to this, except on machines that have at least one private network. – Toby Speight – 2017-08-18T12:12:56.850
Machines don't have IP addresses. Network interfaces do. Fail. – Kaz – 2017-08-18T13:25:55.047
4... and even one network interface can have multiple IP addresses. – Kaz – 2017-08-18T13:26:43.523
The external IP address part is solved with a standard loophole by most answers. – Johannes Kuhn – 2017-08-18T15:25:57.750
What if we have multiple local Ip addresses? Output any one of them? Output all of them? Output a very specific one? – Octopus – 2017-08-18T16:41:20.797
14
Actually, I don't see how you could solve half of this without fetching from an external source, which is one of the standard loopholes you have expressly forbidden.
– Octopus – 2017-08-18T16:50:31.1071@TobySpeight, if you're not behind NAT, then your local and external addresses are the same. This challenge is basically "output the address according to your network interface, and your address according to a remote server". – Mark – 2017-08-18T21:11:42.517
3Surely it's 127.0.0.1... – wizzwizz4 – 2017-08-19T20:28:37.237
Currently my answer is the accepted one even though there are shorter solutions, you should update the accepted answer.. – ბიმო – 2017-12-19T11:09:43.863