470,815 Members | 1,290 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

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?
Jul 19 '05 #1
5 1817

ne******@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, * be*@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
Jul 19 '05 #2
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";

Jul 19 '05 #3
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 <us****@morrow.me.uk> wrote in message news:<c1**********@wisteria.csv.warwick.ac.uk>...
ne******@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

Jul 19 '05 #4
[don't top-post]
[wrap your posts at 72 chars or so]

ne******@yahoo.com (NNTP) wrote:
Ben Morrow <us****@morrow.me.uk> wrote in message
news:<c1**********@wisteria.csv.warwick.ac.uk>...
ne******@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 * be*@morrow.me.uk
Jul 19 '05 #5
That worked great. my bad.

Thanks

Ben Morrow <us****@morrow.me.uk> wrote in message news:<c1**********@wisteria.csv.warwick.ac.uk>...
[don't top-post]
[wrap your posts at 72 chars or so]

ne******@yahoo.com (NNTP) wrote:
Ben Morrow <us****@morrow.me.uk> wrote in message
news:<c1**********@wisteria.csv.warwick.ac.uk>...
ne******@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

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by bry | last post: by
2 posts views Thread by Christoph Borger | last post: by
1 post views Thread by ritesh.noronha | last post: by
reply views Thread by axlq | last post: by
4 posts views Thread by smcoe1 | last post: by
2 posts views Thread by Toby | last post: by
2 posts views Thread by Zhang Weiwu | last post: by
rpnew
2 posts views Thread by rpnew | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.