"Go" Linux How to get IP address by command only

Source: Internet
Author: User
Tags get ip

A colleague's friend is taking part in the written examination, encountered such a problem let him help solve, the result colleague found me to help him to fix. Really feeling: communication developed in some ways, I really do not know is not good ah! The topic is as follows, generally we use ifconfig to view the network card information, what command can you pass, let it only output IP address 192.168.42.128

Seemingly simple problems, and implementation is not too simple. Look at the following ideas.

[Email protected] ~]# ifconfig eth0
inet addr:192.168.42.128 bcast:192.168.42.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FE9E:700E/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:135 errors:0 dropped:0 overruns:0 frame:0
TX packets:216 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:14062 (13.7 KiB) TX bytes:26007 (25.3 KiB)

[Email protected] ~]# ifconfig eth0 | grep "inet Addr"
inet addr:192.168.42.128 bcast:192.168.42.255 mask:255.255.255.0

This is a very simple step, and then it needs to be done with awk, as shown below, to solve this problem.

[Email protected] ~]# ifconfig eth0 | grep "inet addr" | awk ' {print $} '
addr:192.168.42.128
[Email protected] ~]# ifconfig eth0 | grep "inet addr" | awk ' {print $} ' | Awk-f: ' {print $} '
192.168.42.128

"Go" Linux How to get IP address by command only

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.