I need to create a script that outputs the internal IP address, that is configured as the default Interface.
How to display the IP address of the default Interface with Internet connection
ifconfigipnetworkingscripting
ifconfigipnetworkingscripting
I need to create a script that outputs the internal IP address, that is configured as the default Interface.
Best Answer
Here's another slightly terser method using
procfs
(assumes you're using Linux):This returns both the IPv4 and (if available) the IPv6 address of the interface. You can change the test if you only want one or the other (look for
inet
for IPv4, andinet6
for IPv6).