Re: .sh script code to determine IPv4 or IPv6
I have some scripts that do fairly crude IPv4/6 validation testing. It is generally assumed that the input is coming from someone who knows what they are doing, but even the best of us have fat fingers sometimes :) Having standardized routines for something like this is great! Thanks, -Markham On 13-08-06 11:45 AM, Teske, Devin wrote: > On Aug 6, 2013, at 10:39 AM, Polytropon wrote: > >> On Tue, 6 Aug 2013 16:50:37 +, Teske, Devin wrote: >>> And yes... to clarify... the port is a mirror of what's in 9.x base. >>> (however, see my recent notes in a separate reply; TL;DR: port is >>> 9.x only; proceed only if you know you don't care about the dialog(1) >>> aspects of the library code). >> I think it should be relatively unproblematic to fetch the >> port and only use the subroutines "as is", even if it's just >> for educational purposes. :-) >> > Right. > > Just a warning though, what is "fetched" in ports is actually in the format > of what's in HEAD (read: not in the format of what gets installed). > > For example, there are things that end up in /usr/share/bsdconfig that aren't > in the "bsdconfig/share/" source directory (e.g., all the stuff under > /usr/share/bsdconfig/networking is under the source directory > "bsdconfig/networking/share"). This may be counter-intuitive from an > "exploratory" view if looking at the source directory (what's fetched by > ports). > > And since the port Makefile will prevent you from turning that fetch'ed > source directory into an installed software (putting things where they end > up), it might be easier to grab this pre-built package that I stashed... > > http://druidbsd.sf.net/download/bsdconfig/bsdconfig-0.9.0.tbz > > Because then you can say "pkg_add" and everything will be in the right place > (/usr/share/bsdconfig/ will be flush with everything and you won't have to > hunt-and-peck through the source with a "maintainers" view). ___ 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"
Re: .sh script code to determine IPv4 or IPv6
On Aug 6, 2013, at 10:39 AM, Polytropon wrote: > On Tue, 6 Aug 2013 16:50:37 +, Teske, Devin wrote: >> And yes... to clarify... the port is a mirror of what's in 9.x base. >> (however, see my recent notes in a separate reply; TL;DR: port is >> 9.x only; proceed only if you know you don't care about the dialog(1) >> aspects of the library code). > > I think it should be relatively unproblematic to fetch the > port and only use the subroutines "as is", even if it's just > for educational purposes. :-) > Right. Just a warning though, what is "fetched" in ports is actually in the format of what's in HEAD (read: not in the format of what gets installed). For example, there are things that end up in /usr/share/bsdconfig that aren't in the "bsdconfig/share/" source directory (e.g., all the stuff under /usr/share/bsdconfig/networking is under the source directory "bsdconfig/networking/share"). This may be counter-intuitive from an "exploratory" view if looking at the source directory (what's fetched by ports). And since the port Makefile will prevent you from turning that fetch'ed source directory into an installed software (putting things where they end up), it might be easier to grab this pre-built package that I stashed... http://druidbsd.sf.net/download/bsdconfig/bsdconfig-0.9.0.tbz Because then you can say "pkg_add" and everything will be in the right place (/usr/share/bsdconfig/ will be flush with everything and you won't have to hunt-and-peck through the source with a "maintainers" view). -- 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"
Re: .sh script code to determine IPv4 or IPv6
On Tue, 6 Aug 2013 16:50:37 +, Teske, Devin wrote: > And yes... to clarify... the port is a mirror of what's in 9.x base. > (however, see my recent notes in a separate reply; TL;DR: port is > 9.x only; proceed only if you know you don't care about the dialog(1) > aspects of the library code). I think it should be relatively unproblematic to fetch the port and only use the subroutines "as is", even if it's just for educational purposes. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ 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"
Re: .sh script code to determine IPv4 or IPv6
On Aug 6, 2013, at 9:43 AM, Polytropon wrote: > On Tue, 06 Aug 2013 10:20:05 -0600, markham breitbach wrote: >> On 13-08-03 8:04 AM, Teske, Devin wrote: >>> Actually, there's /usr/share/bsdconfig/media/tcpip.subr >>> >>> >> I don't seem to have that (FreeBSD 8.3-RELEASE). >> Where would I get that from? > > Maybe from sysutils/bsdconfig in the ports collection? > I have not checked if this specific subroutine file is > part of the port... > Ah, Polytropon beat me ;D And yes... to clarify... the port is a mirror of what's in 9.x base. (however, see my recent notes in a separate reply; TL;DR: port is 9.x only; proceed only if you know you don't care about the dialog(1) aspects of the library code). -- Devin > > -- > Polytropon > Magdeburg, Germany > Happy FreeBSD user since 4.0 > Andra moi ennepe, Mousa, ... _ 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"
Re: .sh script code to determine IPv4 or IPv6
On Aug 6, 2013, at 9:20 AM, markham breitbach wrote: > On 13-08-03 8:04 AM, Teske, Devin wrote: >> Actually, there's /usr/share/bsdconfig/media/tcpip.subr >> >> > I don't seem to have that (FreeBSD 8.3-RELEASE). Where would I get that > from? > > It's in up-coming 9.2-R (and present 9.2-* snapshots leading up to 9.2-R). You can snatch a copy of the code by installing sysutils/bsdconfig from the ports tree. However, the port is marked (correctly-so) as requiring FreeBSD 9.0 or higher. But don't let that stop you... the only reason it's marked as requiring 9.0 is because 9.0 brings in a new dialog(1) implementation. However, if you're interested in the TCP validation code... that will work on any release. It's only the dialog(1) stuff that won't work on 8.x or older. Luckily, it'll be pretty easy to avoid the land-mines. All functions starting with f_dialog_* should be avoided on 8.x or older. So here's the latest package to download (in case you're unsuccessful in getting the port to behave -- afterall, it may just balk at you for not running 9.x): fetch http://druidbsd.sourceforge.net/download/bsdconfig/bsdconfig-0.9.0.tbz That's a FreeBSD package. You can download it and say (as root): pkg_add bsdconfig-0.9.0.tbz Just be forewarned (again), on 8.x or older, executing "bsdconfig" will have widely unexpected results (it won't eat your homework, but it may or may not actually *run*). However, doing the above 2-step (fetch & pkg_add) will bring in the files you're looking for and give you the functionality you're wanting on 8.x. -- Devin P.S. I really *can't* make the dialog(1) stuff backward compatible with 8.x's (or any older's) version of dialog(1). The new `cdialog' variant that was brought into 9.x to replace the aging dialog(1)/libdialog pair is has a *lot* of functionality that I depend on. It could potentially take months to make bsdconfig *fully* backward compatible with 8.x. For now, it's safe if you just use the libraries and avoid any/all functions beginning with "f_dialog_". _ 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"
Re: .sh script code to determine IPv4 or IPv6
On Tue, 06 Aug 2013 10:20:05 -0600, markham breitbach wrote: > On 13-08-03 8:04 AM, Teske, Devin wrote: > > Actually, there's /usr/share/bsdconfig/media/tcpip.subr > > > > > I don't seem to have that (FreeBSD 8.3-RELEASE). > Where would I get that from? Maybe from sysutils/bsdconfig in the ports collection? I have not checked if this specific subroutine file is part of the port... -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ 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"
Re: .sh script code to determine IPv4 or IPv6
On 13-08-03 8:04 AM, Teske, Devin wrote: > Actually, there's /usr/share/bsdconfig/media/tcpip.subr > > I don't seem to have that (FreeBSD 8.3-RELEASE). Where would I get that from? ___ 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"
Re: .sh script code to determine IPv4 or IPv6
On Aug 3, 2013, at 5:04 AM, Robert Huff wrote: > > Fbsd8 writes: > >> 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? > > Not that I know of. > But ... how hard can it be to figure out whether it uses '.' or > ':'? > Actually, there's /usr/share/bsdconfig/media/tcpip.subr Function family: f_validate_ipaddr6 $ipv6_addr # Should be complete; I digested multiple RFCs on IPv6 f_validate_ipaddr $ipv4_addr [$netmask] # optional netmask to validate IP is within doubly-valid f_validate_hostname $hostname # To RFC specifications 952 and 1123 But if you need to prompt the user to enter a value and then validate it, the above functions return meaningful exit status for determining what's wrong with their entry (why did it fail specification, for example). To help decode the exit status, the functions you want to use are: # In /usr/share/bsdconfig/networking/ipaddr.subr Function family: f_dialog_iperror $status $ipv4_addr f_dialog_ip6error $status $ipv6_addr As is implied with the "_dialog_" in their name, they take the $? exit status from the previously mentioned f_validate_*() functions and display a dialog(1) error appropriate to what's wrong. For example, you might see: ERROR! One or more individual octets within the IPv4 address\n(separated by dots) contains one or more invalid characters.\nOctets must contain only the characters 0-9.\n\nInvalid IP Address: %s or ERROR! The IP address entered has either too few (less than 3), too\nmany (more than 8), or not enough segments, separated by colons.\n\nInvalid IPv6 Address: %s And then, in the same function family above (as the *ip[6]error()): f_dialog_vaildate_ipaddr $ipv4_addr f_dialog_validate_ipaddr6 $ipv6_addr These are like: f_validate_ipaddr $ipv4_addr f_validate_ipaddr6 $ipv6_addr Except as implied by the extra "_dialog_" in their name, they will actually run f_validate_* and then f_dialog_ip[6]error() for you with the result. Finally, last, but not least... The process of actually *getting* the values has been simplified too. In the same family function (as f_dialog_ip[6]error and f_dialog_validate_ipaddr[6]()) is: f_dialog_input_ipaddr $interface $ipaddr # $interface is displayed in the prompt text # $ipaddr is used as default text in the input box If user doesn't press escape or select cancel, $ipaddr will hold the users entry. This function validates, displays errors, and is an all-around solution if you need to prompt the user to enter the info and only proceed if they enter a valid entry (the above function is IPv4 centric and supports CIDR notation). The IPv6 version of the latter (f_dialog_input_ipaddr6) does not yet exist. I'm getting there. For now, if you need to prompt for an entry that could be IPv6, use the generic f_dialog_input() routine and sanitize it with the aforementioned API. -- 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"
Re: .sh script code to determine IPv4 or IPv6
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"
.sh script code to determine IPv4 or IPv6
Fbsd8 writes: > 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? Not that I know of. But ... how hard can it be to figure out whether it uses '.' or ':'? Robert Huff ___ 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"
.sh script code to determine IPv4 or IPv6
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? Thanks ___ 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"