Comando estável para analisar eth0 IP em jessie e stretch

1

Então, algum gênio mudou a maneira como isso é impresso. No Raspberry com Raspbian (Debian Jessie):

$ /sbin/ifconfig eth0
eth0      Link encap:Ethernet  HWaddr b8:27:eb:71:d5:56  
      inet addr:192.168.0.11  Bcast:192.168.0.255  Mask:255.255.255.0
      inet6 addr: fe80::1e43:2c74:e7d6:6419/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:165 errors:0 dropped:0 overruns:0 frame:0
      TX packets:135 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:17459 (17.0 KiB)  TX bytes:18391 (17.9 KiB)

No meu laptop (extensão Debian):

$ /sbin/ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.0.77  netmask 255.255.255.0  broadcast 192.168.0.255
    inet6 fe80::39db:8c13:722f:b088  prefixlen 64  scopeid 0x20<link>
    ether 40:b0:34:96:d9:02  txqueuelen 1000  (Ethernet)
    RX packets 118126  bytes 23261567 (22.1 MiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 319445  bytes 452933203 (431.9 MiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device interrupt 16  memory 0xcc200000-cc220000  

Eu tinha código que analisa "inet addr:" , isso obviamente falha agora no laptop. Existe uma maneira única de obter, usando um comando shell, o endereço IP eth0 em ambos Raspbian / Jessie e Stretch?

    
por 0__ 05.08.2017 / 16:36

1 resposta

2

Isso é formatado de maneira idêntica em ambos os sistemas:

$ ip a show eth0 # stretch
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 40:b0:34:96:d9:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.77/24 brd 192.168.0.255 scope global eth0
   valid_lft forever preferred_lft forever
inet6 fe80::39db:8c13:722f:b088/64 scope link tentative 
   valid_lft forever preferred_lft forever

$ ip a show eth0 # raspbian jessie
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:71:d5:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.11/24 brd 192.168.0.255 scope global eth0
   valid_lft forever preferred_lft forever
inet6 fe80::1e43:2c74:e7d6:6419/64 scope link 
   valid_lft forever preferred_lft forever
    
por 05.08.2017 / 16:46

Tags