Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get native ip in Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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,'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report