

falsy ips like 12345.12.34.1 can be excluded in this. The second regexp after the or looks for ip address in the middle.we are matching it in such a way that the number that follows ,should be exactly 1 to 3 digits. Since all proposed solutions seem to have circumstances where they fail, check for possible edge cases - no eth, multiple eth's & lo's, when would 'hostname -i' fail. First regexp looks for the exact match of ip address in the beginning of the line. You can do this with standard system calls. So to get IP you need to find the IP after src, using awk, sed or grep ip route get 8.8.8.8 | awk -F"src " 'NR=1' )" With newer version of Linux you get more information with a typical output some like this: ip route get 8.8.8.8Ĩ.8.8.8 via 10.36.15.1 dev ens160 src 10.36.15.1 To find what IP adders is used connected to internet, we can use the ip route command. If the goal is to find the IP address connected in direction of internet, then this should be a good solution.Įdit 2021: Added "sed" and "grep" versions and new "awk" versions (some are gnu) If anyone would be interested in it just pm me. I know about grep and sed but I am not really good with them.Įdit: Firstly to say thank you for helping me with this problem, now I know much more. Is there any command that allow me to do such a thing, to search in stream for informations I want to get?. As part of an installation script, I want to make an 'educated guess' about the machines public IP address. I want to display only the IP address in line: echo "Your IP address is: (IP_ADDRESS )". TX packets:2002 errors:0 dropped:0 overruns:0 carrier:0

RX packets:1904 errors:0 dropped:0 overruns:0 frame:0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 For example my ifconfig looks like: eth0 Link encap:Ethernet HWaddr 08:00:27:a3:e3:b0

There is a hostlist named hosts.linux on the server with all the hostnames, just no IPs. I want to use only some of the informations that commands give me. SYNOPSIS./cidr-to-ip. Ive been asked to get a list of hosts and IPs for security to run a scan against those servers. I want to make big script on my Debian 7.3 ( something like translated and much more new user friendly enviroment ).
