commandline version of this script.

Discussion in 'Perl' started by NNTP, Feb 18, 2004.

  1. NNTP

    NNTP Guest

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

    is it even doable?
     
    NNTP, Feb 18, 2004
    #1
    1. Advertising

  2. NNTP

    Ben Morrow Guest

    (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, *
    it is worth reading when you are sixty." - C.S.Lewis
     
    Ben Morrow, Feb 18, 2004
    #2
    1. Advertising

  3. 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";
     
    Exide Arabellan, Feb 18, 2004
    #3
  4. NNTP

    NNTP Guest

    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 <> wrote in message news:<c10dev$a0u$>...
    > (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
     
    NNTP, Feb 19, 2004
    #4
  5. NNTP

    Ben Morrow Guest

    [don't top-post]
    [wrap your posts at 72 chars or so]

    (NNTP) wrote:
    > Ben Morrow <> wrote in message
    > news:<c10dev$a0u$>...
    > > (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, Feb 19, 2004
    #5
  6. NNTP

    NNTP Guest

    That worked great. my bad.

    Thanks

    Ben Morrow <> wrote in message news:<c13b7r$aiv$>...
    > [don't top-post]
    > [wrap your posts at 72 chars or so]
    >
    > (NNTP) wrote:
    > > Ben Morrow <> wrote in message
    > > news:<c10dev$a0u$>...
    > > > (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
     
    NNTP, Feb 20, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. V Green
    Replies:
    0
    Views:
    885
    V Green
    Feb 5, 2008
  2. PA Bear [MS MVP]
    Replies:
    0
    Views:
    1,000
    PA Bear [MS MVP]
    Feb 5, 2008
  3. fatted
    Replies:
    1
    Views:
    163
    Steve Grazzini
    Jul 25, 2003
  4. NNTP
    Replies:
    6
    Views:
    117
  5. IanW
    Replies:
    23
    Views:
    1,046
Loading...

Share This Page