How to get native ip in Linux
This article is about how to get native ip in Linux. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Call shell:
$ip = `ifconfig eth0 | grep-oE'([0-9] {1pm 3}\.) {4}'| head-n 1`
Note: the input here is fixed, so the simple [0-9] {1pr 3}, if you are in the web program and other places to verify ip, you need to be more rigorous!
Or
$ip = `ifconfig eth0 | awk-F:'/ inet addr/ {split ($2J a, "); print a [1]; exit}'`
Well, this seems too non-perl, and frequent calls to external shell are not good, the second way:
Open FH, "ifconfig eth0 |"; while () {last unless / inet addr: (\ d {1Magne3}\.?) {4}) /; print $1;}
It looks a little bit Perl, although it is essentially the same as the above calls to shell and GREP methods.
Third, a little more perl, just read the file:
Open FH,'