• linux 中查看、抽取本机IP


    方法1:

    1、查看ip

    [root@centos7pc1 test]# ifconfig | head
    ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.65.153  netmask 255.255.255.0  broadcast 192.168.65.255
            inet6 fe80::cf50:d12:760f:c2f1  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:c5:9b:14  txqueuelen 1000  (Ethernet)
            RX packets 25490  bytes 26858429 (25.6 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 12793  bytes 1189793 (1.1 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

    2、提取ip

    [root@centos7pc1 test]# ifconfig | grep "inet" | awk 'NR == 1{ print $2 }'
    192.168.65.153

    方法2:

    1、查看ip

    [root@centos7pc1 test]# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
    2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:c5:9b:14 brd ff:ff:ff:ff:ff:ff
        inet 192.168.65.153/24 brd 192.168.65.255 scope global noprefixroute dynamic ens32
           valid_lft 1770sec preferred_lft 1770sec
        inet6 fe80::cf50:d12:760f:c2f1/64 scope link noprefixroute
           valid_lft forever preferred_lft forever
    3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
        link/ether 52:54:00:3a:fc:95 brd ff:ff:ff:ff:ff:ff
        inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
           valid_lft forever preferred_lft forever
    4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
        link/ether 52:54:00:3a:fc:95 brd ff:ff:ff:ff:ff:ff

    2、提取ip

    [root@centos7pc1 test]# ip a | grep "inet" | grep "ens" | awk '{print $2}' | cut -d "/" -f 1
    192.168.65.153
  • 相关阅读:
    Java实现One-way traffic(单向交通)
    Java实现One-way traffic(单向交通)
    Java实现One-way traffic(单向交通)
    Java实现One-way traffic(单向交通)
    C#调用Delphi Dll返回字符串的示例(使用Move才能拷贝字符串)
    Delphi实现菜单项上出现提示
    WebBrowser中获得脚本中的变量值
    比较两个文件是否相同(比较两个流是否相等)
    WebBrowser执行脚本和调用外部方法
    c#之函数创建和闭包
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/16224060.html
Copyright © 2020-2023  润新知