Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //lab 5 client
- #!/usr/bin/perl
- #UDP client
- use IO::Socket::INET;
- use strict;
- my ($MySocket, $def_msg, $msg, $text, $host, $port);
- #takes in host and port as command line arguments
- $host = $ARGV[0];
- $port = $ARGV[1];
- # Create a new socket
- $MySocket=new IO::Socket::INET->new(PeerPort=>$port, Proto=>'udp',PeerAddr=>$host);
- # Send messages
- $def_msg="Enter message to send to server : ";
- print "\n",$def_msg;
- while($msg=<STDIN>)
- {
- chomp $msg;
- if($msg ne '') #if there is a message
- {
- if($MySocket->send($msg))
- {
- print ".....<done>","\n"; #message successfully sent
- if($msg eq "quit"){
- print "Exited\n"; #if client sends quit, exit
- exit 1;
- }
- }
- if($MySocket->recv($text, 128)){ #if a message is received, print it
- print "$text\n";
- }
- }
- else
- {
- # Send an empty message to server and exit
- $MySocket->send('');
- exit 1;
- }
- }
- //lab5 server
- #!/usr/bin/perl
- #UDP Server
- use IO::Socket::INET;
- use strict;
- my ($MySocket, $def_msg, $text, $response, $port);
- #takes in port as a command line argument
- $port = $ARGV[0];
- # Create a new socket
- $MySocket=new IO::Socket::INET->new(LocalPort=>$port,Proto=>'udp');
- # Keep receiving messages from client
- $def_msg="\nReceiving message from client.....\n";
- while(1)
- {
- $MySocket->recv($text,128);
- if($text ne '')
- {
- print "\nReceived message '", $text,"'\n";
- $response = "server:".reverse $text; #responds to client, reverses
- print "$response\n"; #prints server reponse server-side
- $MySocket->send($response); #prints server reponse client-side
- }
- # If client message is empty, they have exited
- else
- {
- print "Client has exited!";
- }
- }
- //lab 5 step 4
- #!/usr/bin/perl
- use Nmap::Scanner;
- use strict;
- my @results;
- my $ipaddr = $ARGV[0]; #File containing list of IPs to scan
- my $num_scan = $ARGV[1]; #Number of Scans to run
- my $sleep = $ARGV[2]; #How long (seconds) to wait between scans
- my $email = $ARGV[3]; #Email to send results to
- my $scanner = new Nmap::Scanner; #new scanner object
- open FH, "$ipaddr" || die $!; #open the ip addresses file
- my @ip = <FH>;
- close(FH);
- foreach my $L(@ip){
- chomp $L;
- $scanner->add_target($L); #adds each IP to list of scans
- }
- for(my $i=0; $i < $num_scan; $i++){
- push (@results, ($scanner->scan())->as_xml()); #scans and converts results
- sleep $sleep; #waits a predetermined amount of time between scans
- }
- if($email =~ m/(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/g){
- sendemail($email, @results); #sends results to email
- }
- else{
- print "Invalid email, results not sent\n";
- }
- #sendmail subroutine, takes in
- #an email and a message
- sub sendemail{
- my $to = $_[0];
- my $msg = $_[1];
- my $from = "bob_saget\@afv.com";
- my $subject = "Output from Nmap::Scanner";
- open(MAIL, "|/usr/sbin/sendmail -t");
- print MAIL "To: $to\n";
- print MAIL "From: $from\n";
- print MAIL "Subject: $subject\n\n";
- print MAIL "Output: $msg";
- close MAIL;
- }
- //
Add Comment
Please, Sign In to add comment