Giter Club home page Giter Club logo

Comments (10)

rgcr avatar rgcr commented on August 22, 2024 1

hello @tnguyen14, try to use printf instead echo

list_netservices(){
    networksetup -listallhardwareports | while IFS= read -r line; do
    # if it is a device we will print the ip in the next line
    if echo ${line} | grep -i "Device" >/dev/null 2>&1; then
        #echo "${line}\nIp: $(ipconfig getifaddr $(echo ${line} | cut -d: -f2 2>/dev/null))"
        printf "${line}\nIP:$(ipconfig getifaddr $(echo ${line} | cut -d: -f2 2>/dev/null))\n"
    else
        #echo ${line}
        printf "${line}\n"
    fi
done

}

I'll update the function soon to avoid this error.

from m-cli.

rgcr avatar rgcr commented on August 22, 2024 1

Hello @REBELinBLUE I've changed this to use printf instead echo in the latest version (v0.1.8), it should work now

from m-cli.

rgcr avatar rgcr commented on August 22, 2024

ifconfig does that, I suppose you want the same functionality but more readeable like the output of m network ls, am I right?

Feel free to create a pull request with your enhancements 👍 😃

from m-cli.

dmuth avatar dmuth commented on August 22, 2024

Yeah, I'm good friends with ifconfig, but it's way too verbose. The output from m is quite readable, and I'd love to see more things like IP addresses in it.

I'll take a whack at the code (not necessarily tonight) and see what I can do.

from m-cli.

dmuth avatar dmuth commented on August 22, 2024

So I did just take a quick look at the code, and it's written in the Bourne Shell. I checked into associative arrays in bash, and they're only support in Bash version 4.

Do we have the option of contributing code in a language other than shell? If so, I'll proceed. (I'm thinking PHP, but more than happy to do Python...)

from m-cli.

rgcr avatar rgcr commented on August 22, 2024

Hello @dmuth I think we need to keep it as simple as possible, so I wrote a simple shell function to do it

This is an example of the output:

Hardware Port: Wi-Fi
Device: en0
Ip: 192.168.1.1
Ethernet Address: AA:BB:CC:DD:EE:FF


Hardware Port: Bluethoot PAN
Device: en4
Ip: 
Ethernet Address: AA:BB:CC:DD:EE:FF

from m-cli.

dmuth avatar dmuth commented on August 22, 2024

I just looked at your solution code, and wasn't aware of the ipconfig command. Had I know that, I would have used it. Nice job!

from m-cli.

tnguyen14 avatar tnguyen14 commented on August 22, 2024

@rgcr I just tried using your solution


list_netservices(){
    networksetup -listallhardwareports | while IFS= read -r line; do
        # if it is a device we will print the ip in the next line
        if echo ${line} | grep -i "Device" >/dev/null 2>&1; then
            echo "${line}\nIp: $(ipconfig getifaddr $(echo ${line} | cut -d: -f2 2>/dev/null))"
        else
            echo ${line}
        fi
    done
}

I'm seeing this in the output

:; list_netservices

Hardware Port: Wi-Fi
Device: en0\nIp: 10.200.13.17
Ethernet Address: 78:31:c1:d0:3f:20

Hardware Port: Bluetooth PAN
Device: en4\nIp:
Ethernet Address: 78:31:c1:d0:3f:21

Hardware Port: Thunderbolt 1
Device: en1\nIp:
Ethernet Address: 72:00:02:b4:7b:20

I'm guessing the \n is not formatted correctly?

from m-cli.

tnguyen14 avatar tnguyen14 commented on August 22, 2024

@rgcr that works great. thanks!

from m-cli.

REBELinBLUE avatar REBELinBLUE commented on August 22, 2024

In the latest version I am not getting the newline, rather the escape character

Hardware Port: Targus USB3 DV1K-2K Compact Doc
Device: en7\nIp: 10.152.29.116
Ethernet Address: 00:50:b6:cc:46:23

from m-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.