[Question]
  [
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](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply so shortest code wins.
[Standard Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) 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.
  
[Answer]
# Bash + [curl](https://curl.haxx.se/) + [iproute2](https://wiki.linuxfoundation.org/networking/iproute2), ~~54 50 49 48~~ 33 bytes
```
ip r g 1|awk '$0=$7'
curl eth0.me
```
Thanks @DomHastings for golfing off 1 byte!
Thanks @Sisyphus for coming up with a shorter URL!
Thanks @zeppelin for golfing off 9 bytes!
[Answer]
# Bash 37 31 27 bytes
This is inspired by the [answer](https://codegolf.stackexchange.com/a/139538/21461) by [Bruce Forte](https://codegolf.stackexchange.com/users/48198/bruce-forte). That answer only works with IPv4 which means it doesn't work for me. I have rewritten it into a version that (only) works with IPv6:
```
ip r g b::|awk '$0=$9" "$9'
```
This is tested on Ubuntu 14.04.5 connected through PPPoE and since IPv6 is designed to be used without any NAT it will output the same IP address twice.
-6 bytes thanks to [zeppelin](https://codegolf.stackexchange.com/users/61904/zeppelin),
-2 bytes thanks to [Ferrybig](https://codegolf.stackexchange.com/users/10621/ferrybig),
-2 bytes thanks to [Markasoftware](https://codegolf.stackexchange.com/users/10973/markasoftware).
[Answer]
# AutoIt, ~~56~~ 53 bytes
```
#include<Inet.au3>
ConsoleWrite(@IPAddress1&_GetIP())
```
[`@IPAddress1`](https://www.autoitscript.com/autoit3/docs/macros.htm) is a macro that returns
> 
> IP address of first network adapter
> 
> 
> 
[`_GetIP()`](https://www.autoitscript.com/autoit3/docs/libfunctions/_GetIP.htm) returns
> 
> the public IP address.
> 
> 
> 
---
-3 bytes thanks to @mınxomaτ
[Answer]
# Mathematica, 17 bytes
~~Mathematica has a builtin for everything~~
```
$MachineAddresses
```
[As described in the documentation](http://reference.wolfram.com/language/ref/$MachineAddresses.html), this builtin command lists all IP addresses (both local and external) associated with your device.
[Answer]
# C#, ~~196~~ ~~194~~ ~~188~~ 163 bytes
```
namespace System.Net.Sockets{using Linq;_=>Dns.GetHostEntry("").AddressList.First(i=>(int)i.AddressFamily==2)+" "+new WebClient().DownloadString("http://eth0.me")}
```
*Saved 2 bytes thanks to @Xynos.*  
*Saved 25 bytes thanks to @Nick.*
Full/Formatted Version:
```
namespace System.Net.Sockets
{
    using Linq;
    class P
    {
        static void Main()
        {
            Func<object, string> f = _ =>
                Dns.GetHostEntry(Dns.GetHostName())
                    .AddressList
                    .First(i => (int)i.AddressFamily == 2) + " " + new WebClient().DownloadString("http://eth0.me");
            Console.WriteLine(f(null));
            Console.ReadLine();
        }
    }
}
```
[Answer]
## PowerShell v4+, 40 36 bytes
```
NetIPAddress|% IPA*
iwr eth0.me|% C*
```
*(Only works on Server 2012 R2 or above, or Windows 8.1 or above. Doesn't work on TIO.)*
Does exactly what it says on the tin. Gets the local network IP addresses and selects just the `IPA`ddress portion thereof (e.g., filters out the subnet mask, the gateway, etc.).
The second is a `Invoke-WebRequest` to `http://eth0.me` which simply gets the `C`ontent thereof; i.e., just the public IP address.
---
Ungolfed version:
```
(Get-NetIPAddress).IPAddress
(Invoke-WebRequest eth0.me).content
```
[Answer]
#Unix Shell + [stunclient](http://manpages.ubuntu.com/manpages/zesty/man1/stunclient.1.html), 40 bytes
```
stunclient stun.vo.lu|cut -d: -f2|sed 1d
```
Makes use of a [STUN protocol](https://www.rfc-editor.org/rfc/rfc5389):
> 
> Session Traversal Utilities for NAT (STUN) is a protocol that serves
> as a tool for other protocols in dealing with Network Address
> Translator (NAT) traversal. It can be used by an endpoint to
> determine the IP address and port allocated to it by a NAT
> 
> 
> 
The STUN server name is from the [Public STUN server list](https://gist.github.com/mondain/b0ec1cf5f60ae726202e).
The output format is:
```
 LOCAL IPV4 ADDRESS
 PUBLIC IPV4 ADDRESS
```
Note that both lines will be indented with a single space, but I believe this does not break the output rules as written.
Sample output:
```
  192.168.1.100    
  209.85.233.147
```
[Answer]
# curl (bash one-liner): 27 bytes
```
curl -w%{local_ip} eth0.me
```
The result is printed on `stdout` and looks like this: 
```
1.2.3.4
192.168.0.10
# no trailing newline, use "curl -w%{local_ip}\\n eth0.me" for it
```
`curl` should be at least of version 7.29.0 (from Feb 6, 2013).
The answer is based on <https://codegolf.stackexchange.com/a/139538/66016>.
[Answer]
## Go, MacOS only, 10 bytes
In macOS this [killswitch](https://vpn-kill-switch.com/) could be used, it can print current private active IP and public IP:
```
$ killswitch 
Interface  MAC address         IP
en1        bc:34:36:d2:81:ba   192.168.2.10
Public IP address: 179.43.176.99
No VPN interface found, verify VPN is connected
```
This is not a built-in tool but tries to simplify the process of finding the proper IP's.
The output could get by using commands like:
```
$ route get 0.0.0.0
$ ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'
$ networksetup -listnetworkserviceorder
$ scutil --dns
```
Public IP:
```
$ dig o-o.myaddr.l.google.com @ns.google.com txt +short
```
[Answer]
**Python 3, 124 133 bytes**
```
from urllib2 import urlopen
import socket
a=urlopen('http://eth0.me').read()
b=socket.gethostbyname(socket.gethostname())
print a,b
```
[Answer]
**PowerShell v3+ (alternative answer for windows 7+)**
```
((ipconfig) -match "v4").split(":")[1]
Invoke-RestMethod eth0.me
```
[Answer]
# Bash + Awk + Curl, 43 bytes
using only built in tools for Mac and Linux
```
ifconfig|awk '/bro/{print $2}';curl eth0.me
```
[Answer]
## Node.js (JavaScript) ~~224~~ ~~223~~ ~~194~~ ~~175~~ ~~173~~ 130 bytes
```
r=require,l=console.log,r('dns').lookup(r('os').hostname(),(a,b)=>l(b));r('http').get('http://eth0.me',a=>a.on('data',c=>l(c+"")))
```
Ungolfed version:
```
require('dns').lookup(require('os').hostname(), (err, loc, fam) => console.log(loc));
require('http').get('http://eth0.me', res => {
    res.on('data', chunk => console.log(chunk + ""));
});
```
---
* *Saved 1 byte* (due to unnecessary semicolon).
* *Saved 29 bytes thanks to @AndrewLi* (used arrow functions for shorter code).
* *Saved 19 bytes thanks to @MiniGod* (used `.get()` instead of `.request()` - `.end();` removed).
* *Saved 2 bytes thanks to @Zacharý* (parentheses not needed around a lone parameter of an arrow function).
* *Saved 43 bytes thanks to @Birjolaxew* (stored `require` and `console.log` in single-letter variables, passed url directly to `require('http').get`, logged output directly from `data` event).
[Answer]
**Python 2.7.13 128 bytes**
```
print __import__("urllib").urlopen("http://eth0.me").read(),__import__("socket").gethostbyname(__import__("socket").getfqdn())
```
[Answer]
# [Windows' Batch File](https://en.wikipedia.org/wiki/Batch_file), 116 bytes
```
@for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "v4"')do @echo%%b
@powershell -Command "(iwr eth0.me).content"
```
The first line iterates through the results of running `ipconfig` and gets your local IPv4 address.
For the public IP part, I had to steal a bit from the marvelous [Powershell answer](https://codegolf.stackexchange.com/a/139556/66000) because, as far as I know, there is no way to get the machine's public IP using solely batch scripting.
We start with an `@` sign, to suppress echoing the prompt (`C:\...\path>`), then run the Powershell command `Invoke-WebRequest` (with its alias, `iwr`) and extract the `content` part of that.
I experimented with *not* using `(...).content` and, instead, only running the command and extracting the actual information from the complete output, using batch. But that proved to be way longer than this solution, so I kept it.
Tested on Windows 10.0.15063.
[Answer]
## R, ~~142~~, ~~140~~, 137 bytes
```
library(magrittr);system("ipconfig",int=T)%>%regmatches(.,regexpr("v4.+",.))%>%{a=nchar(.);substr(.,a-14,a)};readLines("http://eth0.me")
```
Tested on win10 and R (3.4.1).  
Thanks for @Bruce-Forte for short URL. 
Ungolfed version:
```
library(magrittr)
system("ipconfig",int=T) %>% 
     regmatches(.,regexpr("v4.+",.)) %>% 
      {a <- nchar(.)
       substr(., a - 14, a)}
readLines("http://eth0.me")
```
[Answer]
# Bash + Curl, 24 bytes
```
hostname -i;curl eth0.me
```
[Answer]
# MS-SQL, 59 bytes
```
SELECT TOP 1 local_net_address
FROM sys.dm_exec_connections
```
Returns the client-facing IP address of the SQL instance executing the query.
[Answer]
# VBA, 58 Bytes
***Whoops, does not handle local address - fix in progress***
> 
> ***Note:***
>  Uses reference to
> 
> 
> `Microsoft Internet Controls`
> 
> 
> 
Anonymous VBE immediate window function that takes no input and outputs the user's IP address via an Internet Explorer window
```
Set i=New InternetExplorer:i.Visible=1:i.Navigate"eth0.me"
```
[Answer]
# Bash — 29 bytes (linux)
```
curl ipinfo.io/ip
hostname -i
```
[Answer]
# [Python 3](https://docs.python.org/3/), 97 bytes
```
from socket import*
from requests import*
gethostbyname(gethostname()),get('http://eth0.me').text
```
returns tuple with `('LOCAL_IP', 'PUBLIC_IP')`, as apparently
```
x = 2,3
type(x)
>>> tuple
```
# [Python 3](https://docs.python.org/3/), 103 bytes
```
from socket import*
from requests import*
gethostbyname(gethostname()),get('http://api.ipify.org').text
```
ditto, read below.
---
# [Python 3](https://docs.python.org/3/), 107 bytes
First solution
```
from socket import*
from requests import*
gethostbyname(gethostname())+" "+get('http://api.ipify.org').text
```
The `+" "+` part is for joining strings together.
If you leave just the `+` sign, 103 bytes are possible, but would yield the strings without spaces which could lead to results like this `"5.5.5.111222.222.222.222"` and they should still be readable, as there are only 3 digits at max in every ip part.
But there are edge cases like `"5.5.5.11111.222.222.222"` where it would be impossible to distinguish the local vs public part.
Other possible savings are in the public ip grabber tool. I used this site, as it was the first thing I found on the Internet and it returns html with just text in it, which is super nice. I saw other people using `http://eth0.me`, but it doesn't load for me on my machine and my antivirus has it blacklisted, thus Python raises a `ConnectionError`. It loads through Tor though, so I don't know whether I should use it.
# [Python 3](https://docs.python.org/3/), 101 bytes
```
from socket import*
from requests import*
gethostbyname(gethostname())+" "+get('http://eth0.me').text
```
]