• linux 得到内网*ip


    原文

    1. Get Internal IP Address(es) on Linux Shell / Command Line

    1.1 Get Single IP Address by Interface

    Returns plain IP address.

    /sbin/ifconfig $1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
     
    ## Example usage ##
    /sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
    10.20.10.1

    Create simple bash function (example int-ip) with following command.

    function int-ip { /sbin/ifconfig $1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'; }
     
    ## Example usage ##
    int-ip eth0
    10.20.10.1
     

    1.2 Get Every Interfaces IP Address

    Returns every interface and IP address pairs.

    /sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'
     
    ## Example output ##
    eth0: 10.20.10.1
    eth1: 10.20.1.168
    lo: 127.0.0.1

    Create simple bash function (example int-ips) with following command.

    function int-ips { /sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'; }
     
    ## Example usage ##
    int-ips
    eth0: 10.20.10.1
    eth1: 10.20.1.168
    lo: 127.0.0.1
     

    2. Get External IP Address on Linux Shell / Command Line

    I use here whatismyip.org service.

    2.1 Get External IP Address Using Lynx

    Returns plain IP address.

    lynx --dump http://ipecho.net/plain
     
    ## Example output ##
    80.10.10.80

    已验证

    Create simple bash function (example ext-ip) with following command.

    function ext-ip () { lynx --dump http://ipecho.net/plain; }
     
    ## Example usage ##
    ext-ip
    80.10.10.80
     

    2.2 Get External IP Address Using Curl

    Returns plain IP address.

    curl http://ipecho.net/plain; echo
     
    ## Example output ##
    80.10.10.80

    Create simple bash function (example ext-ip) with following command.

    function ext-ip () { curl http://ipecho.net/plain; echo; }
     
    ## Example usage ##
    ext-ip
    80.10.10.80
  • 相关阅读:
    Code-EncryptDecrypt:DES
    Code-Helper:EncryptHelper.cs
    Code-Helper:EmailHelper.cs
    养生-影视:《长寿之道——长寿村里的百岁夫妻》
    影视-栏目:《致富经》
    影视-栏目:《远方的家》
    影视-纪录片:《长江行》
    影视-纪录片:《塔里木河》
    影视-纪录片:《天山脚下》
    Counting Lines, Words, and Characters with wc
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2967061.html
Copyright © 2020-2023  润新知