Header Banner
Null Byte Logo
Null Byte
wonderhowto.mark.png
Cyber Weapons Lab Forum Metasploit Basics Facebook Hacks Password Cracking Top Wi-Fi Adapters Wi-Fi Hacking Linux Basics Mr. Robot Hacks Hack Like a Pro Forensics Recon Social Engineering Networking Basics Antivirus Evasion Spy Tactics MitM Advice from a Hacker

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.

You already know how to use your phone. With Gadget Hacks' newsletter, we'll show you how to master it. Each week, we explore features, hidden tools, and advanced settings that give you more control over iOS and Android than most users even know exists.

Sign up for Gadget Hacks Weekly and start unlocking your phone's full potential.

Related Articles

Comments

No Comments Exist

Be the first, drop a comment!