Useful code snippets and commands for Linux.

Ralph using a computer.

Alternatives to the ping and traceroute commands on a Linux system There are many alternatives to the ping and traceroute commands on a Linux system. The mtr command is one of them. This command will trace the route the network packets are taking to the target IP address. bash 06:42:02 Mon Jul 22 [homer@deep-thought $ … Read more

A script I wrote that checks whether a host is reachable by various protocols like ICMP & TCP.

A nice script that will check if a host is up or not. #!/usr/bin/perl   use warnings; use strict;   use Net::Ping;   # code source: http://www.perlmonks.org/?node_id=943892 # More: http://stackoverflow.com/questions/3960595/how-can-i-ping-a-host-with-a-perl-one-liner-with-netping   #$| = 1; print "Please type a host to check: -:\n"; my $host = <>; #Reading input from STDIN.   if (length($host) < 3) … Read more

Voyager probe leaving us and thoughts on the end of the world and Perl.

The Voyager probe is finally approaching the edge of the heliosphere; the massive sphere that encloses the entire solar system; very soon the lonely probe will finally be entering deep space and it will be truly alone. This probe is travelling at just about 38,000 miles per hour and it is destined to encounter another … Read more

Networking script I am working on. This prints some information about your machine.

This Perl script will print some information about your networking set-up on your Linux machine. #!/usr/bin/perl   use warnings;   $iface = "eth0";   @data = `ifconfig`;   $net = $data[1];   $kernel = `uname -r`;   printf("\n*————————————-*\n");   printf("The IP of %s is:%s\n", $iface, $net); printf("The kernel version is: %s\n", $kernel);   printf("\n*————————————-*\n");#!/usr/bin/perl use … Read more

Wrapping the printf() statement onto multiple lines in C and some other useful samples.

This code sample shows how we are wrapping a printf() statement onto multiple lines using backslashes. #include "stdio.h"   #define hello "Hello World."   int main(int argc, char* argv[]) { printf("This is a very long sentence we are handing down\n"\ "Mr smith, do you have anything to say for yourself"\ "?");   printf("%s\n", hello);   … Read more

Miscellaneous Perl programming information. How to use for loops and printing HTML properly.

Opening a folder and listing the contents, and not listing certain files. This is the Perl code I was using on my very old Tripod.com website. opendir(DNAME, "$folder") || die "I cannot open the requested directory $folder \n $!"; @dirfiles2 = readdir (DNAME); @dirfiles2 = sort(@dirfiles2); foreach $x2 (@dirfiles2) { if ($x2 eq ".") { … Read more