Get local IP address from "ip route" cross-platform

nikoskip

I'm trying to extract the local IP address using a cross-platform command. Until today, I was using this command:

ip route get 1 | awk '{print $NF;exit}'

But on Fedora 27 is not working because the output of ip route get 1 is:

0.0.0.1 via 192.168.1.1 dev en1  src 192.168.0.229 uid 1000
    cache

And I'm getting 1000 as the IP address. In all other systems that I have tried, the output has been always:

0.0.0.1 via 192.168.1.1 dev en1  src 192.168.0.229

I also tried using this command with same result:

ip route get 255.255.255.255 | sed -n '/src/ s/.*src //p'
Stephen Kitt

To print the address coming just after src (assuming all the relevant parts stay on the same line...):

ip route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q'

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

ip route mentinoning GW

分類Dev

VPS IP address for local site

分類Dev

Is it possible to SCP from a remote to local whilst logged into the remote and without knowing the local's IP address?

分類Dev

How to get IP address from controller's hosts file in Ansible?

分類Dev

How to get the ip address of a computer from its hostname?

分類Dev

Get IP Address used to connect to Firebase from Android device

分類Dev

Virtualbox: get host IP address

分類Dev

extracting ip address from a file

分類Dev

ip route save binaryまたはascii?

分類Dev

ip route 複数のエントリ

分類Dev

how to attach a static IP address programmatically (Python) in Google Cloud Platform

分類Dev

Get just an IP address only from `ipconfig` using native windows command

分類Dev

Qt get external IP address using QNetworkReply

分類Dev

Get IP address of domain with Unicode characters?

分類Dev

apt-get — Specify source IP address

分類Dev

How to know a mac address for a Node knowing its IP on local network?

分類Dev

JavaScript net.connect() - explicitly set local endpoint IP address

分類Dev

APIPA (link-local) IP address in Windows Registry

分類Dev

Extracting ip address and interface name from ifconfig

分類Dev

How to block an IP address from a network share

分類Dev

How to mount from an IP address using NFS?

分類Dev

Getting MAC Address of devices using Local Network IP Address(192.168.xxx.xxx)

分類Dev

ip route delはテーブル全体を削除しません

分類Dev

Assign LAN IP address to Docker container different from host's IP address

分類Dev

how can i get clients ip address on UDP server in golang?

分類Dev

How to get client IP address in Laravel 5+

分類Dev

get ip address by domain with dns.lookup() node.js

分類Dev

how to get container host machine ip address and container name in EKS

分類Dev

How to get k8s master ip address?

Related 関連記事

  1. 1

    ip route mentinoning GW

  2. 2

    VPS IP address for local site

  3. 3

    Is it possible to SCP from a remote to local whilst logged into the remote and without knowing the local's IP address?

  4. 4

    How to get IP address from controller's hosts file in Ansible?

  5. 5

    How to get the ip address of a computer from its hostname?

  6. 6

    Get IP Address used to connect to Firebase from Android device

  7. 7

    Virtualbox: get host IP address

  8. 8

    extracting ip address from a file

  9. 9

    ip route save binaryまたはascii?

  10. 10

    ip route 複数のエントリ

  11. 11

    how to attach a static IP address programmatically (Python) in Google Cloud Platform

  12. 12

    Get just an IP address only from `ipconfig` using native windows command

  13. 13

    Qt get external IP address using QNetworkReply

  14. 14

    Get IP address of domain with Unicode characters?

  15. 15

    apt-get — Specify source IP address

  16. 16

    How to know a mac address for a Node knowing its IP on local network?

  17. 17

    JavaScript net.connect() - explicitly set local endpoint IP address

  18. 18

    APIPA (link-local) IP address in Windows Registry

  19. 19

    Extracting ip address and interface name from ifconfig

  20. 20

    How to block an IP address from a network share

  21. 21

    How to mount from an IP address using NFS?

  22. 22

    Getting MAC Address of devices using Local Network IP Address(192.168.xxx.xxx)

  23. 23

    ip route delはテーブル全体を削除しません

  24. 24

    Assign LAN IP address to Docker container different from host's IP address

  25. 25

    how can i get clients ip address on UDP server in golang?

  26. 26

    How to get client IP address in Laravel 5+

  27. 27

    get ip address by domain with dns.lookup() node.js

  28. 28

    how to get container host machine ip address and container name in EKS

  29. 29

    How to get k8s master ip address?

ホットタグ

アーカイブ