Perl for the Aspiring Hacker (Control Statements)

Oct 25, 2015 12:39 AM

In this tutorial we will be go over how we can make use of conditionals.

In Perl the main conditional is the if statement. The if statement in

Perl is used like this:

If (example){

#code

} else {

#execute a different type of code than above.

It is literally that simple! I know, right?

Let's make something cool with that.

#!/usr/bin/perl

use Net::Ping;

$host = "8.26.65.101";

$example = Net::Ping->new("icmp", 1, 64);

if ($example->ping($host)) {

print "$host is very much alive.\n";

} else {

print "$host is dead. Hopefully he resurrects.\n";

So, let's review the source code. First we start with the Shebang. After the shebang we use a Perl Module, "NET::PING;". This might be the first time you see "Net::Ping;" if you're new to Perl. This module specifically exists to do ping functions. After that, we gave an IP address to the $host variable so it can than feed the IP to the module. We than say that we want to send our ping by ICMP (OTW covered what ICMP is I believe.). We than setup an 'if' statement that will tell us if the host returned with any errors. If it did, than the script will return with a "8.26.65.101 is dead. Hopefully he resurrects." If the host returns with 0 errors, it'll come back with '"Host is very much alive."

That is all for today! Thank you.

Related Articles

637263493835297420.jpg

How to Use Zero-Width Characters to Hide Secret Messages in Text (& Even Reveal Leaks)

636455706472146367.jpg

How to Hide DDE-Based Attacks in MS Word

Comments

No Comments Exist

Be the first, drop a comment!