Linux: Find my IP address using Perl at a shell prompt

Linux: Find my IP address using Perl at a shell prompt

To find your IP address using Perl at a shell prompt on a Linux system, you can use the following command:

perl -e 'use Socket;$i="$ENV{SERVER_NAME}";$p="$ENV{SERVER_PORT}";if($i eq ""){$i=inet_ntoa(scalar gethostbyname(""))}print "Your IP address is: $i\n";'
Source:ww‮.w‬lautturi.com

This command will use the Socket module in Perl to determine your IP address and print it to the console. If your system is behind a router or firewall, this command will return the internal IP address of your system on the local network. If you want to determine your external IP address, you can use a service such as http://checkip.dyndns.org/.

Alternatively, you can use the ifconfig command to display your system's network configuration, including the IP address of each network interface. To display only the IP address of a specific interface, you can use the ifconfig command with the inet option, followed by the name of the interface. For example:

ifconfig eth0 inet

This will display the IP address of the Ethernet interface named eth0.

Created Time:2017-10-30 10:17:45  Author:lautturi