Solved

How do I get a list of all the ipaddresses in one string?

Posted on 2013-02-06
2
257 Views
Last Modified: 2013-02-07
Hi
How do I get a list of all the ipaddresses (that is not 127.0.0.1) in one string?
IPv4 and IPv6 addresses.
so return "IP:10.20.30.1, IP:10.20.30.2, IP:3030:0:110:715:150:51ff:fe82:4f15"

Thanks
Jamie
0
Comment
Question by:jamie_lynn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
bevhost earned 500 total points
ID: 38862398
#!/bin/bash
for line in `ip addr show | grep inet | grep -v host | cut -d\  -f6 | cut -d/ -f1 `; do
        if [ "x$str" == "x" ]; then
                str="IP:$line"
        else
                str="$str, IP:$line"
        fi
done
echo $str

Open in new window

0
 

Author Closing Comment

by:jamie_lynn
ID: 38865027
Works great! Thanks!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question