Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   commandline version of this script. (http://www.velocityreviews.com/forums/t885284-commandline-version-of-this-script.html)

NNTP 02-18-2004 06:50 PM

commandline version of this script.
 
#!/usr/bin/perl
use Validate::Net;
if ( Validate::Net->ip($ARGV[0]))
{
print "valid";
exit 0;
}
print "invalid";
#--done

is it even doable?

Ben Morrow 02-18-2004 07:12 PM

Re: commandline version of this script.
 

news8080@yahoo.com (NNTP) wrote:
> #!/usr/bin/perl
> use Validate::Net;
> if ( Validate::Net->ip($ARGV[0]))
> {
> print "valid";
> exit 0;
> }
> print "invalid";
> #--done
>
> is it even doable?


err... (untested)

perl -MValidate::Net -le'print !Validate::Net->ip(shift) && "in", "valid"'

Ben

--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis

Exide Arabellan 02-18-2004 07:13 PM

Re: commandline version of this script.
 
NNTP wrote:
> #!/usr/bin/perl
> use Validate::Net;
> if ( Validate::Net->ip($ARGV[0]))
> {
> print "valid";
> exit 0;
> }
> print "invalid";
> #--done
>
> is it even doable?


Worked for me. Here is the script i used:

#!/usr/bin/perl -w

use strict;
use Validate::Net;

if (Validate::Net->ip($ARGV[0])) {
print "valid\n";
exit 0;
}
print "invalid\n";


gnari 02-18-2004 08:18 PM

Re: commandline version of this script.
 
[removing newsgroups from followup, among others an invalid one]

"NNTP" <news8080@yahoo.com> wrote in message
news:110fc16.0402181050.1a88d36a@posting.google.co m...
> #!/usr/bin/perl
> use Validate::Net;
> if ( Validate::Net->ip($ARGV[0]))
> {
> print "valid";
> exit 0;
> }
> print "invalid";
> #--done
>
> is it even doable?


I am wondering what your problem is.

<mantra>
what did you try ?
what happened ?
what did you expect to happen ?
</mantra>

gnari




NNTP 02-19-2004 09:37 PM

Re: commandline version of this script.
 
This script does work but what I am trying to do is call it from
another script and I don't want to have 2 scripts if I can just
replace this script with a command like Ben suggested,

perl -MValidate::Net -le'print \!Validate::Net->ip(shift) && "in",
"valid"'
doesn't work

sh-2.05a# ./validateip.pl 1.1.1.1
valid
sh-2.05a# ./validateip.pl 1.1.1.1asdfdasf
invalid
sh-2.05a# cat validateip.pl
#!/usr/bin/perl
use Validate::Net;
if ( Validate::Net->ip($ARGV[0]))
{
print "valid
";
exit 0;
}
print "invalid
";
sh-2.05a# perl -MValidate::Net -le'print \!Validate::Net->ip(1.1.1.1)
&& "in", "valid"'
invalid
sh-2.05a# perl -MValidate::Net -le'print \!Validate::Net->ip(1.1.11.)
&& "in", "valid"'
syntax error at -e line 1, near ".) "
Execution of -e aborted due to compilation errors.
sh-2.05a# perl -MValidate::Net -le'print
\!Validate::Net->ip(1.1.1.1asdfdasf) && "in", "valid"'
Bareword found where operator expected at -e line 1, near
"1.1.1.1asdfdasf"
(Missing operator before asdfdasf?)
syntax error at -e line 1, near "1.1.1.1asdfdasf"
Execution of -e aborted due to compilation errors.




Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c10dev$a0u$9@wisteria.csv.warwick.ac.uk>...
> news8080@yahoo.com (NNTP) wrote:
> > #!/usr/bin/perl
> > use Validate::Net;
> > if ( Validate::Net->ip($ARGV[0]))
> > {
> > print "valid";
> > exit 0;
> > }
> > print "invalid";
> > #--done
> >
> > is it even doable?

>
> err... (untested)
>
> perl -MValidate::Net -le'print !Validate::Net->ip(shift) && "in", "valid"'
>
> Ben


Ben Morrow 02-19-2004 09:52 PM

Re: commandline version of this script.
 
[don't top-post]
[wrap your posts at 72 chars or so]

news8080@yahoo.com (NNTP) wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<c10dev$a0u$9@wisteria.csv.warwick.ac.uk>...
> > news8080@yahoo.com (NNTP) wrote:
> > >
> > > #!/usr/bin/perl
> > > use Validate::Net;
> > > if ( Validate::Net->ip($ARGV[0]))
> > > {
> > > print "valid";
> > > exit 0;
> > > }
> > > print "invalid";
> > > #--done
> > >
> > > is it even doable?

> >
> > err... (untested)
> >
> > perl -MValidate::Net -le'print !Validate::Net->ip(shift) && "in", "valid"'

>
> perl -MValidate::Net -le'print \!Validate::Net->ip(shift) && "in",
> "valid"'
> doesn't work
>
> sh-2.05a# perl -MValidate::Net -le'print \!Validate::Net->ip(1.1.1.1)
> && "in", "valid"'
> invalid
> sh-2.05a# perl -MValidate::Net -le'print \!Validate::Net->ip(1.1.11.)
> && "in", "valid"'
> syntax error at -e line 1, near ".) "
> Execution of -e aborted due to compilation errors.
> sh-2.05a# perl -MValidate::Net -le'print
> \!Validate::Net->ip(1.1.1.1asdfdasf) && "in", "valid"'
> Bareword found where operator expected at -e line 1, near
> "1.1.1.1asdfdasf"
> (Missing operator before asdfdasf?)
> syntax error at -e line 1, near "1.1.1.1asdfdasf"
> Execution of -e aborted due to compilation errors.


Try using it right:

~% perl -MValidate::Net -le'print !Validate::Net->ip("1.1.1.1")
&& "in", "valid"'
valid
~% perl -MValidate::Net -le'print !Validate::Net->ip("1.1.1.1adad")
&& "in", "valid"'
invalid
~% perl -MValidate::Net -le'print !Validate::Net->ip("1.1.11.")
&& "in", "valid"'
invalid

or, better,

#!/bin/sh

VALID_IP=$(<<CMD
perl -MValidate::Net -le'print !Validate::Net->ip(shift) && "in", "valid"'
CMD
)

eval $VALID_IP 1.1.1.1
eval $VALID_IP 1.1.11.
eval $VALID_IP 1.1.1.1adsf

Ben

--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else * ben@morrow.me.uk

NNTP 02-20-2004 05:17 PM

Re: commandline version of this script.
 
That worked great. my bad.

Thanks

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c13b7r$aiv$1@wisteria.csv.warwick.ac.uk>...
> [don't top-post]
> [wrap your posts at 72 chars or so]
>
> news8080@yahoo.com (NNTP) wrote:
> > Ben Morrow <usenet@morrow.me.uk> wrote in message
> > news:<c10dev$a0u$9@wisteria.csv.warwick.ac.uk>...
> > > news8080@yahoo.com (NNTP) wrote:
> > > >
> > > > #!/usr/bin/perl
> > > > use Validate::Net;
> > > > if ( Validate::Net->ip($ARGV[0]))
> > > > {
> > > > print "valid";
> > > > exit 0;
> > > > }
> > > > print "invalid";
> > > > #--done
> > > >
> > > > is it even doable?
> > >
> > > err... (untested)
> > >
> > > perl -MValidate::Net -le'print !Validate::Net->ip(shift) && "in", "valid"'

> >
> > perl -MValidate::Net -le'print \!Validate::Net->ip(shift) && "in",
> > "valid"'
> > doesn't work
> >
> > sh-2.05a# perl -MValidate::Net -le'print \!Validate::Net->ip(1.1.1.1)
> > && "in", "valid"'
> > invalid
> > sh-2.05a# perl -MValidate::Net -le'print \!Validate::Net->ip(1.1.11.)
> > && "in", "valid"'
> > syntax error at -e line 1, near ".) "
> > Execution of -e aborted due to compilation errors.
> > sh-2.05a# perl -MValidate::Net -le'print
> > \!Validate::Net->ip(1.1.1.1asdfdasf) && "in", "valid"'
> > Bareword found where operator expected at -e line 1, near
> > "1.1.1.1asdfdasf"
> > (Missing operator before asdfdasf?)
> > syntax error at -e line 1, near "1.1.1.1asdfdasf"
> > Execution of -e aborted due to compilation errors.

>
> Try using it right:
>
> ~% perl -MValidate::Net -le'print !Validate::Net->ip("1.1.1.1")
> && "in", "valid"'
> valid
> ~% perl -MValidate::Net -le'print !Validate::Net->ip("1.1.1.1adad")
> && "in", "valid"'
> invalid
> ~% perl -MValidate::Net -le'print !Validate::Net->ip("1.1.11.")
> && "in", "valid"'
> invalid
>
> or, better,
>
> #!/bin/sh
>
> VALID_IP=$(<<CMD
> perl -MValidate::Net -le'print !Validate::Net->ip(shift) && "in", "valid"'
> CMD
> )
>
> eval $VALID_IP 1.1.1.1
> eval $VALID_IP 1.1.11.
> eval $VALID_IP 1.1.1.1adsf
>
> Ben



All times are GMT. The time now is 05:45 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.