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)

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.

Apple's iOS 26 and iPadOS 26 updates are packed with new features, and you can try them before almost everyone else. First, check Gadget Hacks' list of supported iPhone and iPad models, then follow the step-by-step guide to install the iOS/iPadOS 26 beta — no paid developer account required.

Related Articles

Comments

No Comments Exist

Be the first, drop a comment!