Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use the ip command #84

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

fix: use the ip command #84

wants to merge 4 commits into from

Conversation

BoboTiG
Copy link
Contributor

@BoboTiG BoboTiG commented Jul 27, 2024

Now using ip (which is available since at least 2011).

  • fix: stick with ip for the route check

The new code is more readable and contains less lines actually. But I needed to keep the macOS compatibility, so that's why the patch is more important.

If the macOs support can be dropped, then I could simplify more, LMK.

BoboTiG added 2 commits July 27, 2024 14:32
Now using `ip` (which is available since at least 2011).
bin/detect_ips.sh Outdated Show resolved Hide resolved
(( ( ip & mask ) == ( gw & mask ) )) &&
int2ip $ip myIp && int2ip $mask netMask
}
}
done < <(/sbin/ifconfig)
done < <(ip -4 -c=never -br addr)
Copy link
Contributor Author

@BoboTiG BoboTiG Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of output from such a command:

lo                  UNKNOWN       127.0.0.1/8 
enp4s0             UP             192.168.2.10/24 
br-23a6b14a9fa6  DOWN           172.18.0.1/16 
br-4abc919a1eb3  DOWN           172.20.0.1/16 
docker0            UP             172.17.0.1/16 
br-b804039dfb11  DOWN           172.19.0.1/16

Comment on lines 53 to 55
while IFS=$' :\t\r\n' read before netmask after; do
mask=$netmask
done < <(/usr/bin/ipcalc -n -b $rhs | grep Netmask)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will convert IP/24 to 255.255.255.0.

@BoboTiG

This comment was marked as outdated.

@BoboTiG BoboTiG marked this pull request as draft July 27, 2024 13:37
@BoboTiG BoboTiG marked this pull request as ready for review July 27, 2024 13:48
@HDauven HDauven requested a review from herr-seppia September 2, 2024 12:04
@HDauven
Copy link
Member

HDauven commented Sep 2, 2024

Awesome @BoboTiG! Thanks a lot.

I'll put @herr-seppia as reviewer, as I can't test it properly this week. Looks very good though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ifconfig is outdated
2 participants