Want to write a script to do the batch conversion from domain name to IP.

Discussion in 'Perl Misc' started by Hongyi Zhao, Jan 30, 2009.

  1. Hongyi Zhao

    Hongyi Zhao Guest

    Hi all,

    Suppose I've the entries like the following in my file:

    ------------------
    116.52.155.237:80
    ip-72-55-191-6.static.privatedns.com:3128
    222.124.135.40:80
    217.151.231.34:3128
    202.106.121.134:80
    211.161.197.182:80
    hpc.be.itu.edu.tr:80
    static3-117-183.worldinternetworkcorporation.com:80
    ------------------

    Now, I want to convert the domain name to IP by using a perl script,
    any hints on this?

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 30, 2009
    #1
    1. Advertising

  2. Re: Want to write a script to do the batch conversion from domainname to IP.

    Hongyi Zhao wrote:
    > Hi all,
    >
    > Suppose I've the entries like the following in my file:
    >
    > ------------------
    > 116.52.155.237:80
    > ip-72-55-191-6.static.privatedns.com:3128
    > 222.124.135.40:80
    > 217.151.231.34:3128
    > 202.106.121.134:80
    > 211.161.197.182:80
    > hpc.be.itu.edu.tr:80
    > static3-117-183.worldinternetworkcorporation.com:80
    > ------------------
    >
    > Now, I want to convert the domain name to IP by using a perl script,
    > any hints on this?
    >


    I'd use split /:/ to separate the address from the port number.

    I'd use a regular expression to check if the address looks like an
    ip-address. If your are confident of your data you can be a bit sloppy
    and use something simple like m/^[0-9.]+$/ Otherwise read this
    http://www.perlmonks.org/?node_id=221512

    For addresses that look like a hostname+domain I'd use gethostbyname

    --
    RGB
     
    RedGrittyBrick, Jan 30, 2009
    #2
    1. Advertising

  3. Re: Want to write a script to do the batch conversion from domainname to IP.

    Hongyi Zhao wrote:
    >
    > Suppose I've the entries like the following in my file:
    >
    > ------------------
    > 116.52.155.237:80
    > ip-72-55-191-6.static.privatedns.com:3128
    > 222.124.135.40:80
    > 217.151.231.34:3128
    > 202.106.121.134:80
    > 211.161.197.182:80
    > hpc.be.itu.edu.tr:80
    > static3-117-183.worldinternetworkcorporation.com:80
    > ------------------
    >
    > Now, I want to convert the domain name to IP by using a perl script,
    > any hints on this?


    $ echo "
    116.52.155.237:80
    ip-72-55-191-6.static.privatedns.com:3128
    222.124.135.40:80
    217.151.231.34:3128
    202.106.121.134:80
    211.161.197.182:80
    hpc.be.itu.edu.tr:80
    static3-117-183.worldinternetworkcorporation.com:80
    " | perl -MSocket -lne'
    my $address = ( split /:/ )[ 0 ] or next;
    my $number = inet_aton $address;
    my $ip = inet_ntoa $number;
    print "$address -> $ip";
    '
    116.52.155.237 -> 116.52.155.237
    ip-72-55-191-6.static.privatedns.com -> 72.55.191.6
    222.124.135.40 -> 222.124.135.40
    217.151.231.34 -> 217.151.231.34
    202.106.121.134 -> 202.106.121.134
    211.161.197.182 -> 211.161.197.182
    hpc.be.itu.edu.tr -> 160.75.90.69
    static3-117-183.worldinternetworkcorporation.com -> 203.145.117.183



    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
     
    John W. Krahn, Jan 30, 2009
    #3
  4. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 03:04:18 -0800, "John W. Krahn"
    <> wrote:

    >Hongyi Zhao wrote:
    >>
    >> Suppose I've the entries like the following in my file:
    >>
    >> ------------------
    >> 116.52.155.237:80
    >> ip-72-55-191-6.static.privatedns.com:3128
    >> 222.124.135.40:80
    >> 217.151.231.34:3128
    >> 202.106.121.134:80
    >> 211.161.197.182:80
    >> hpc.be.itu.edu.tr:80
    >> static3-117-183.worldinternetworkcorporation.com:80
    >> ------------------
    >>
    >> Now, I want to convert the domain name to IP by using a perl script,
    >> any hints on this?

    >
    >$ echo "
    >116.52.155.237:80
    >ip-72-55-191-6.static.privatedns.com:3128
    >222.124.135.40:80
    >217.151.231.34:3128
    >202.106.121.134:80
    >211.161.197.182:80
    >hpc.be.itu.edu.tr:80
    >static3-117-183.worldinternetworkcorporation.com:80
    >" | perl -MSocket -lne'
    >my $address = ( split /:/ )[ 0 ] or next;
    >my $number = inet_aton $address;
    >my $ip = inet_ntoa $number;
    >print "$address -> $ip";
    >'
    >116.52.155.237 -> 116.52.155.237
    >ip-72-55-191-6.static.privatedns.com -> 72.55.191.6
    >222.124.135.40 -> 222.124.135.40
    >217.151.231.34 -> 217.151.231.34
    >202.106.121.134 -> 202.106.121.134
    >211.161.197.182 -> 211.161.197.182
    >hpc.be.itu.edu.tr -> 160.75.90.69
    >static3-117-183.worldinternetworkcorporation.com -> 203.145.117.183
    >
    >
    >
    >John


    Very good, thanks a lot, it does the trick.

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 30, 2009
    #4
  5. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 03:04:18 -0800, "John W. Krahn"
    <> wrote:
    >$ echo "
    >116.52.155.237:80
    >ip-72-55-191-6.static.privatedns.com:3128
    >222.124.135.40:80
    >217.151.231.34:3128
    >202.106.121.134:80
    >211.161.197.182:80
    >hpc.be.itu.edu.tr:80
    >static3-117-183.worldinternetworkcorporation.com:80
    >" | perl -MSocket -lne'
    >my $address = ( split /:/ )[ 0 ] or next;
    >my $number = inet_aton $address;
    >my $ip = inet_ntoa $number;
    >print "$address -> $ip";
    >'
    >116.52.155.237 -> 116.52.155.237
    >ip-72-55-191-6.static.privatedns.com -> 72.55.191.6
    >222.124.135.40 -> 222.124.135.40
    >217.151.231.34 -> 217.151.231.34
    >202.106.121.134 -> 202.106.121.134
    >211.161.197.182 -> 211.161.197.182
    >hpc.be.itu.edu.tr -> 160.75.90.69
    >static3-117-183.worldinternetworkcorporation.com -> 203.145.117.183


    In my case, I also want the port number be preserved in the result,
    i.e.,

    ip-72-55-191-6.static.privatedns.com:3128

    should be converted into the following:

    72.55.191.6:3128

    What revision should be done on the above code to achieve this aim?

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 30, 2009
    #5
  6. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 03:04:18 -0800, "John W. Krahn"
    <> wrote:
    >$ echo "
    >116.52.155.237:80
    >ip-72-55-191-6.static.privatedns.com:3128
    >222.124.135.40:80
    >217.151.231.34:3128
    >202.106.121.134:80
    >211.161.197.182:80
    >hpc.be.itu.edu.tr:80
    >static3-117-183.worldinternetworkcorporation.com:80
    >" | perl -MSocket -lne'
    >my $address = ( split /:/ )[ 0 ] or next;
    >my $number = inet_aton $address;
    >my $ip = inet_ntoa $number;
    >print "$address -> $ip";
    >'
    >116.52.155.237 -> 116.52.155.237
    >ip-72-55-191-6.static.privatedns.com -> 72.55.191.6
    >222.124.135.40 -> 222.124.135.40
    >217.151.231.34 -> 217.151.231.34
    >202.106.121.134 -> 202.106.121.134
    >211.161.197.182 -> 211.161.197.182
    >hpc.be.itu.edu.tr -> 160.75.90.69
    >static3-117-183.worldinternetworkcorporation.com -> 203.145.117.183


    Based on your code, I use the following lines in my case:

    #!/usr/bin/perl
    cat mydomain.txt | perl -MSocket -lne'
    my $address = ( split /:/ )[ 0 ] or next;
    my $number = inet_aton $address;
    my $ip = inet_ntoa $number;
    print "$address -> $ip";
    '
    Where, mydomain.txt include all of the domain names and IP addresses
    which I want to deal with. Then, I meet the error like this:

    Bad name after lne' at ./11.pl line 2.

    On the other hand, if I remove the first line, i.e.,

    #!/usr/bin/perl

    it will works.

    Why?

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 30, 2009
    #6
  7. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 19:33:35 +0800, Hongyi Zhao
    <> wrote:
    >In my case, I also want the port number be preserved in the result,
    >i.e.,
    >
    >ip-72-55-191-6.static.privatedns.com:3128
    >
    >should be converted into the following:
    >
    >72.55.191.6:3128
    >
    >What revision should be done on the above code to achieve this aim?


    I've sorted it out by using the following code snippet:

    cat cybersyndrome.pla5.txt | perl -MSocket -lne'
    my $address = ( split /:/ )[ 0 ] or next;
    my $port = ( split /:/ )[ 1 ] or next;
    my $number = inet_aton $address;
    my $ip = inet_ntoa $number;
    print "$address:$port -> $ip:$port";
    '

    Thanks again.

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 30, 2009
    #7
  8. Hongyi Zhao <> wrote:
    >cat cybersyndrome.pla5.txt | perl -MSocket -lne'


    Of course this has nothing to do with Perl, nevertheless it's useless
    use of cat, see http://partmaps.org/era/unix/award.html

    jue
     
    Jürgen Exner, Jan 30, 2009
    #8
  9. Re: Want to write a script to do the batch conversion from domainname to IP.

    Hongyi Zhao wrote:
    > On Fri, 30 Jan 2009 03:04:18 -0800, "John W. Krahn"
    > <> wrote:
    >> $ echo "
    >> 116.52.155.237:80
    >> ip-72-55-191-6.static.privatedns.com:3128
    >> 222.124.135.40:80
    >> 217.151.231.34:3128
    >> 202.106.121.134:80
    >> 211.161.197.182:80
    >> hpc.be.itu.edu.tr:80
    >> static3-117-183.worldinternetworkcorporation.com:80
    >> " | perl -MSocket -lne'
    >> my $address = ( split /:/ )[ 0 ] or next;
    >> my $number = inet_aton $address;
    >> my $ip = inet_ntoa $number;
    >> print "$address -> $ip";
    >> '
    >> 116.52.155.237 -> 116.52.155.237
    >> ip-72-55-191-6.static.privatedns.com -> 72.55.191.6
    >> 222.124.135.40 -> 222.124.135.40
    >> 217.151.231.34 -> 217.151.231.34
    >> 202.106.121.134 -> 202.106.121.134
    >> 211.161.197.182 -> 211.161.197.182
    >> hpc.be.itu.edu.tr -> 160.75.90.69
    >> static3-117-183.worldinternetworkcorporation.com -> 203.145.117.183

    >
    > In my case, I also want the port number be preserved in the result,
    > i.e.,
    >
    > ip-72-55-191-6.static.privatedns.com:3128
    >
    > should be converted into the following:
    >
    > 72.55.191.6:3128
    >
    > What revision should be done on the above code to achieve this aim?




    perl -MSocket -lne'
    my ( $address, $port ) = split /:/ or next;
    my $number = inet_aton $address;
    my $ip = inet_ntoa $number;
    print "$address -> $ip:$port";
    '




    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
     
    John W. Krahn, Jan 30, 2009
    #9
  10. Re: Want to write a script to do the batch conversion from domainname to IP.

    Hongyi Zhao wrote:
    > On Fri, 30 Jan 2009 03:04:18 -0800, "John W. Krahn"
    > <> wrote:
    >> $ echo "
    >> 116.52.155.237:80
    >> ip-72-55-191-6.static.privatedns.com:3128
    >> 222.124.135.40:80
    >> 217.151.231.34:3128
    >> 202.106.121.134:80
    >> 211.161.197.182:80
    >> hpc.be.itu.edu.tr:80
    >> static3-117-183.worldinternetworkcorporation.com:80
    >> " | perl -MSocket -lne'
    >> my $address = ( split /:/ )[ 0 ] or next;
    >> my $number = inet_aton $address;
    >> my $ip = inet_ntoa $number;
    >> print "$address -> $ip";
    >> '
    >> 116.52.155.237 -> 116.52.155.237
    >> ip-72-55-191-6.static.privatedns.com -> 72.55.191.6
    >> 222.124.135.40 -> 222.124.135.40
    >> 217.151.231.34 -> 217.151.231.34
    >> 202.106.121.134 -> 202.106.121.134
    >> 211.161.197.182 -> 211.161.197.182
    >> hpc.be.itu.edu.tr -> 160.75.90.69
    >> static3-117-183.worldinternetworkcorporation.com -> 203.145.117.183

    >
    > Based on your code, I use the following lines in my case:
    >
    > #!/usr/bin/perl
    > cat mydomain.txt | perl -MSocket -lne'
    > my $address = ( split /:/ )[ 0 ] or next;
    > my $number = inet_aton $address;
    > my $ip = inet_ntoa $number;
    > print "$address -> $ip";
    > '
    > Where, mydomain.txt include all of the domain names and IP addresses
    > which I want to deal with. Then, I meet the error like this:
    >
    > Bad name after lne' at ./11.pl line 2.
    >
    > On the other hand, if I remove the first line, i.e.,
    >
    > #!/usr/bin/perl
    >
    > it will works.
    >
    > Why?


    Because with that line Perl will try to run it and fail but without that
    line the shell will run it successfully.

    If you want to save the program in the file '11.pl' then use this:

    #!/usr/bin/perl
    use warnings;
    use strict;
    use Socket;

    while ( <> ) {
    chomp;
    my ( $address, $port ) = split /:/ or next;
    my $number = inet_aton $address;
    my $ip = inet_ntoa $number;
    print "$address:$port -> $ip:$port\n";
    }

    __END__


    And then run it as:

    ../11.pl mydomain.txt




    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
     
    John W. Krahn, Jan 30, 2009
    #10
  11. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 05:17:00 -0800, "John W. Krahn"
    <> wrote:
    >Because with that line Perl will try to run it and fail but without that
    >line the shell will run it successfully.


    Thanks, I've got it.

    >
    >If you want to save the program in the file '11.pl' then use this:
    >
    >#!/usr/bin/perl
    >use warnings;
    >use strict;
    >use Socket;
    >
    >while ( <> ) {
    > chomp;
    > my ( $address, $port ) = split /:/ or next;
    > my $number = inet_aton $address;
    > my $ip = inet_ntoa $number;
    > print "$address:$port -> $ip:$port\n";
    > }
    >
    >__END__
    >
    >
    >And then run it as:
    >
    >./11.pl mydomain.txt


    If I want to redirect the output to a file, say myIP.txt, I know that
    the following line will be OK:

    ../11.pl mydomain.txt > myIP.txt

    But, it should be also possiable to redirect the output to a file
    within the above perl script, any hints on this?

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 30, 2009
    #11
  12. Hongyi Zhao <> wrote:
    > On Fri, 30 Jan 2009 05:17:00 -0800, "John W. Krahn"
    ><> wrote:



    >>#!/usr/bin/perl
    >>use warnings;
    >>use strict;
    >>use Socket;



    my $outfile = '/some/other/myIP.txt';
    open my $OTHER, '>', $outfile or die "could not open '$outfile' $!";


    >>while ( <> ) {
    >> chomp;
    >> my ( $address, $port ) = split /:/ or next;
    >> my $number = inet_aton $address;
    >> my $ip = inet_ntoa $number;
    >> print "$address:$port -> $ip:$port\n";



    print $OTHER "$address:$port -> $ip:$port\n";


    >> }
    >>
    >>__END__
    >>
    >>
    >>And then run it as:
    >>
    >>./11.pl mydomain.txt

    >
    > If I want to redirect the output to a file, say myIP.txt, I know that
    > the following line will be OK:
    >
    > ./11.pl mydomain.txt > myIP.txt
    >
    > But, it should be also possiable to redirect the output to a file
    > within the above perl script, any hints on this?
    >



    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Jan 30, 2009
    #12
  13. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 08:52:33 -0600, Tad J McClellan
    <> wrote:

    >Hongyi Zhao <> wrote:
    >> On Fri, 30 Jan 2009 05:17:00 -0800, "John W. Krahn"
    >><> wrote:

    >
    >
    >>>#!/usr/bin/perl
    >>>use warnings;
    >>>use strict;
    >>>use Socket;

    >
    >
    > my $outfile = '/some/other/myIP.txt';
    > open my $OTHER, '>', $outfile or die "could not open '$outfile' $!";


    I use the following two lines:

    my $outfile = '~/myIP.txt';
    open my $OTHER, '>', $outfile or die "could not open '$outfile' $!";

    But, I'll mee the errors like this:

    $ ./DomainName2IP.pl cybersyndrome.pla5.txt
    Missing comma after first argument to open function at
    ../DomainName2IP.pl line 1
    3, near "'>>./you.txt';"
    Execution of ./DomainName2IP.pl aborted due to compilation errors.

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 30, 2009
    #13
  14. Hongyi Zhao <> wrote:
    > On Fri, 30 Jan 2009 08:52:33 -0600, Tad J McClellan
    ><> wrote:



    >> my $outfile = '/some/other/myIP.txt';
    >> open my $OTHER, '>', $outfile or die "could not open '$outfile' $!";

    >
    > I use the following two lines:
    >
    > my $outfile = '~/myIP.txt';
    > open my $OTHER, '>', $outfile or die "could not open '$outfile' $!";



    Using tilde (~) to mean "home directory" is a shell feature.

    Perl is not the shell, so that feature is not available.

    my $outfile = '/home/zhao/myIP.txt';
    or
    my $outfile = 'myIP.txt'; # write to current directory
    or
    my $outfile = './myIP.txt'; # same thing


    > But, I'll mee the errors like this:
    >
    > $ ./DomainName2IP.pl cybersyndrome.pla5.txt
    > Missing comma after first argument to open function at
    > ./DomainName2IP.pl line 1
    > 3, near "'>>./you.txt';"

    ^^^^^^^
    ^^^^^^^

    Where did "you.txt" come from?

    Are you sure you have the right code going with the right error message?



    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Jan 30, 2009
    #14
  15. Hongyi Zhao

    Ted Zlatanov Guest

    On Fri, 30 Jan 2009 11:27:44 -0600 Tad J McClellan <> wrote:

    TJM> Using tilde (~) to mean "home directory" is a shell feature.

    TJM> Perl is not the shell, so that feature is not available.

    Well, glob("~/.cshrc") works OK for me, so the feature is available. It
    uses File::Glob in recent Perls...

    Ted
     
    Ted Zlatanov, Jan 30, 2009
    #15
  16. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 11:27:44 -0600, Tad J McClellan
    <> wrote:

    >> But, I'll mee the errors like this:
    >>
    >> $ ./DomainName2IP.pl cybersyndrome.pla5.txt
    >> Missing comma after first argument to open function at
    >> ./DomainName2IP.pl line 1
    >> 3, near "'>>./you.txt';"

    > ^^^^^^^
    > ^^^^^^^
    >
    >Where did "you.txt" come from?
    >
    >Are you sure you have the right code going with the right error message?


    You're right, there's a bug line in the code used by me, which is come
    from the previous attempt by me.

    I've sorted it out, thanks again.

    Regards,

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 31, 2009
    #16
  17. Re: Want to write a script to do the batch conversion from domainname to IP.

    On 2009-01-30 17:27, Tad J McClellan <> wrote:
    > Hongyi Zhao <> wrote:
    >> On Fri, 30 Jan 2009 08:52:33 -0600, Tad J McClellan
    >><> wrote:
    >>> my $outfile = '/some/other/myIP.txt';
    >>> open my $OTHER, '>', $outfile or die "could not open '$outfile' $!";

    >>
    >> I use the following two lines:
    >>
    >> my $outfile = '~/myIP.txt';
    >> open my $OTHER, '>', $outfile or die "could not open '$outfile' $!";

    >
    >
    > Using tilde (~) to mean "home directory" is a shell feature.
    >
    > Perl is not the shell, so that feature is not available.
    >
    > my $outfile = '/home/zhao/myIP.txt';


    Only if the $HOME is '/home/zhao'.

    my $outfile = "$ENV{HOME}/myIP.txt";

    is the equivalent to ~/myIP.txt.

    (or use glob, as Ted suggested)

    hp
     
    Peter J. Holzer, Jan 31, 2009
    #17
  18. Hongyi Zhao

    Hongyi Zhao Guest

    On Fri, 30 Jan 2009 05:17:00 -0800, "John W. Krahn"
    <> wrote:

    >#!/usr/bin/perl
    >use warnings;
    >use strict;
    >use Socket;
    >
    >while ( <> ) {
    > chomp;
    > my ( $address, $port ) = split /:/ or next;
    > my $number = inet_aton $address;
    > my $ip = inet_ntoa $number;
    > print "$address:$port -> $ip:$port\n";
    > }
    >
    >__END__


    If I want to do the opposite thing, i.e., conversion from IP to domain
    name, what should I revise this script to do the trick.

    In fact, I've post another news on this thing, but that script meet
    errors in my case, and furthermore, it looks more complex then this
    one.

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Jan 31, 2009
    #18
  19. Re: Want to write a script to do the batch conversion from domainname to IP.

    Hongyi Zhao wrote:
    > On Fri, 30 Jan 2009 05:17:00 -0800, "John W. Krahn"
    > <> wrote:
    >
    >> #!/usr/bin/perl
    >> use warnings;
    >> use strict;
    >> use Socket;
    >>
    >> while ( <> ) {
    >> chomp;
    >> my ( $address, $port ) = split /:/ or next;
    >> my $number = inet_aton $address;
    >> my $ip = inet_ntoa $number;
    >> print "$address:$port -> $ip:$port\n";
    >> }
    >>
    >> __END__

    >
    > If I want to do the opposite thing, i.e., conversion from IP to domain
    > name, what should I revise this script to do the trick.



    #!/usr/bin/perl
    use warnings;
    use strict;
    use Socket;

    while ( <> ) {
    chomp;
    my ( $address, $port ) = split /:/ or next;
    my $number = inet_aton $address;
    my $name = gethostbyaddr $number, AF_INET;
    print "$address:$port -> $name:$port\n";
    }

    __END__




    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
     
    John W. Krahn, Jan 31, 2009
    #19
  20. Hongyi Zhao

    Hongyi Zhao Guest

    On Sat, 31 Jan 2009 08:53:47 -0800, "John W. Krahn"
    <> wrote:

    >Hongyi Zhao wrote:
    >> On Fri, 30 Jan 2009 05:17:00 -0800, "John W. Krahn"
    >> <> wrote:
    >>
    >>> #!/usr/bin/perl
    >>> use warnings;
    >>> use strict;
    >>> use Socket;
    >>>
    >>> while ( <> ) {
    >>> chomp;
    >>> my ( $address, $port ) = split /:/ or next;
    >>> my $number = inet_aton $address;
    >>> my $ip = inet_ntoa $number;
    >>> print "$address:$port -> $ip:$port\n";
    >>> }
    >>>
    >>> __END__

    >>
    >> If I want to do the opposite thing, i.e., conversion from IP to domain
    >> name, what should I revise this script to do the trick.

    >
    >
    >#!/usr/bin/perl
    >use warnings;
    >use strict;
    >use Socket;
    >
    >while ( <> ) {
    > chomp;
    > my ( $address, $port ) = split /:/ or next;
    > my $number = inet_aton $address;
    > my $name = gethostbyaddr $number, AF_INET;
    > print "$address:$port -> $name:$port\n";
    > }
    >
    >__END__


    Thanks a lot, John.

    Thanks for others who give me helps or constructive advices again.

    Regards,

    --
    ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
     
    Hongyi Zhao, Feb 1, 2009
    #20
    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. Replies:
    11
    Views:
    716
    William Park
    Jan 30, 2006
  2. Hongyi Zhao
    Replies:
    6
    Views:
    3,299
    Hongyi Zhao
    Jan 31, 2009
  3. Chem Leakhina
    Replies:
    2
    Views:
    145
    Robert Klemme
    Jun 23, 2009
  4. Batch POD Conversion

    , Sep 9, 2005, in forum: Perl Misc
    Replies:
    8
    Views:
    168
  5. Dave Griffith

    Image::Magick->Write() doesn't want to write

    Dave Griffith, Nov 16, 2009, in forum: Perl Misc
    Replies:
    2
    Views:
    231
    Dave Griffith
    Nov 16, 2009
Loading...

Share This Page