Date: Sat, 3 Aug 2013 13:37:09 +0000 From: "Teske, Devin" <Devin.Teske@fisglobal.com> To: Fbsd8 <fbsd8@a1poweruser.com> Cc: Devin Teske <dteske@freebsd.org>, questions <questions@FreeBSD.org> Subject: Re: .sh script code to determine IPv4 or IPv6 Message-ID: <13CA24D6AB415D428143D44749F57D7202002127@ltcfiswmsgmb21> In-Reply-To: <51FCE9C7.7020407@a1poweruser.com> References: <51FCE9C7.7020407@a1poweruser.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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. >=20 > Is there some .sh command that does this? >=20 In RELENG_9, soon to be released 9.2-R: =3D=3D=3D FILE: wis =3D=3D=3D #!/bin/sh DEVICE_SELF_SCAN_ALL=3D . /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 =3D=3D=3D END FILE =3D=3D=3D dteske@scribe9.vicor.com ~ $ ./wis ::1 Hey, nice IPv6 addr, great job! dteske@scribe9.vicor.com ~ $ ./wis 0::1 Hey, nice IPv6 addr, great job! dteske@scribe9.vicor.com ~ $ ./wis 0:::1 What on Earth wast, _that_?! dteske@scribe9.vicor.com ~ $ ./wis 1.2.3.4 Hey, nice IPv4 addr; smiles dteske@scribe9.vicor.com ~ $ ./wis 0.2.3.4 Hey, nice IPv4 addr; smiles dteske@scribe9.vicor.com ~ $ ./wis 256.2.3.4 Hey, nice hostname dteske@scribe9.vicor.com ~ $ ./wis foo.bar.com Hey, nice hostname dteske@scribe9.vicor.com ~ $ ./wis abc-123 Hey, nice hostname dteske@scribe9.vicor.com ~ $ ./wis abc_123 What on Earth wast, _that_?! --=20 Cheers, Devin _____________ The information contained in this message is proprietary and/or confidentia= l. If you are not the intended recipient, please: (i) delete the message an= d all copies; (ii) do not disclose, distribute or use the message in any ma= nner; and (iii) notify the sender immediately. In addition, please be aware= that any message addressed to our domain is subject to archiving and revie= w by persons other than the intended recipient. Thank you.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?13CA24D6AB415D428143D44749F57D7202002127>