On Aug 3, 2013, at 4:30 AM, Fbsd8 wrote:

> I have a .sh script that I need to determine if the entered IP address
> is IPv4 or IPv6.
> 
> Is there some .sh command that does this?
> 

In RELENG_9, soon to be released 9.2-R:

=== FILE: wis ===
#!/bin/sh
DEVICE_SELF_SCAN_ALL=
. /usr/share/bsdconfig/media/tcpip.subr
if f_validate_ipaddr6 "$1"; then
        echo "Hey, nice IPv6 addr, great job!"
elif f_validate_ipaddr "$1"; then
        echo "Hey, nice IPv4 addr; smiles"
elif f_validate_hostname "$1"; then
        echo "Hey, nice hostname"
else
        echo "What on Earth wast, _that_?!"
        exit 1
fi
=== END FILE ===

dte...@scribe9.vicor.com ~ $ ./wis ::1
Hey, nice IPv6 addr, great job!
dte...@scribe9.vicor.com ~ $ ./wis 0::1
Hey, nice IPv6 addr, great job!
dte...@scribe9.vicor.com ~ $ ./wis 0:::1
What on Earth wast, _that_?!
dte...@scribe9.vicor.com ~ $ ./wis 1.2.3.4
Hey, nice IPv4 addr; smiles
dte...@scribe9.vicor.com ~ $ ./wis 0.2.3.4
Hey, nice IPv4 addr; smiles
dte...@scribe9.vicor.com ~ $ ./wis 256.2.3.4
Hey, nice hostname
dte...@scribe9.vicor.com ~ $ ./wis foo.bar.com
Hey, nice hostname
dte...@scribe9.vicor.com ~ $ ./wis abc-123
Hey, nice hostname
dte...@scribe9.vicor.com ~ $ ./wis abc_123
What on Earth wast, _that_?!


-- 
Cheers,
Devin

_____________
The information contained in this message is proprietary and/or confidential. 
If you are not the intended recipient, please: (i) delete the message and all 
copies; (ii) do not disclose, distribute or use the message in any manner; and 
(iii) notify the sender immediately. In addition, please be aware that any 
message addressed to our domain is subject to archiving and review by persons 
other than the intended recipient. Thank you.
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to