Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/perl -w
# Converts an integer number representing an IP back into an IP address string
use strict;
sub ip_to_int ($)
{
my $addr = shift @_;
return unpack("N", pack("C4", split(/\./, $addr)));
#!/usr/bin/perl -w
# Converts an IP address string to a single integer number
use strict;
sub ip_to_int ($)
{
my $addr = shift @_;
return unpack("N", pack("C4", split(/\./, $addr)));
#!/usr/bin/perl -w
# Without parameters, the script displays all the CIDRs and corresponding networks.
# The script will also demonstrate convering a netmask back into a CIDR, but it
# appears that conversion is broken and needs to be looked at.
#
# With parameters, if display network netmask, broadcast, etc info about each IP
# address provided on the command line.
#
# Ultimately, this script intends to demostrate reusable functions that can be
#!/usr/bin/perl -w
# Without parameters, the script displays the current date in three different
# formats (epoch, julian, and gregorian). Here is a example run:
#
# $ ./complicated_date.pl
# epoch: 1471012564 Fri Aug 12 10:36:04 2016
# julian: 2457613.10837963
# gregorian: 1471012564 Fri Aug 12 10:36:03 2016
#
#/bin/bash
# This script demonstrates how to create a queue of items to work
# from and then process X number of jobs in parallel, increasing
# speed and efficiency. Adjust MAX_JOBS according to how many
# items from the queue should be ran in parallel. This script
# preloads the queue with stuff from the home directory just as
# a demonstration.
### Keep track of the number of children processing queue items
#!/bin/sh
# This script displays all the packages installed on a RedHat/CentOS system
# with additional information about installation time sorted by most recently
# installed packages first. This is useful when looking at what packages
# were recently updated.
#
# $ ./rpm_query.sh | head
# 1449154458 Thu 03 Dec 2015 02:54:18 PM UTC filesystem-3.2-20.el7.x86_64
# 1449154458 Thu 03 Dec 2015 02:54:18 PM UTC libgcc-4.8.5-4.el7.x86_64
#!/usr/bin/perl -w
## This script listens for a UDP message on a port containing the text "hello".
## The listener will respond back to the client with its own "hello" string.
## Clients can send messages to this listener using netcat. The following works:
## echo hello | nc -4u -w1 <listener_hostname> <listener_port>
## Substitute the hostname and port for where this listener is running from.
## Keep in mind that ports less than 1024 will require the listener to run as root.
##
## The listener does not yet take any command line options.
#!/usr/bin/perl -w
## This script listens for UDP messages on a port and hexdumps them to the screen.
## The listener will not send any response back to the client. It receives only.
## Clients can send messages to this listener using netcat. The following works:
## echo hello | nc -4u -w1 <listener_hostname> <listener_port>
## Substitute the hostname and port for where this listener is running from.
## Keep in mind that ports less than 1024 will require the listener to run as root.
##
## The listener does not yet take any command line options.
###
## Working bash_profile file.
###
# MacPorts
export PATH=/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:~/bin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
export PS1="[\u@\h \W]$ "
test $WINDOW && PS1="[\u@\h$$WINDOW \W]\$ "
#!/usr/bin/perl -w
use strict;
###
## This demonstrates how you can include BEGIN and END blocks in
## a perl script, but they don't necessarily execute in the order
## that they appear in the script. Here is the output when run:
##
## $ ./begin_end_perl_test.pl