I was going through the published Infoblox /wapidoc documentation and decided to write a shell script that gives me the ability to bulk add/delete Infoblox HOST records at my office. This script uses cURL to post against an Infoblox grid master. You will need to make sure your user account has API permissions and the DNS zone association for the IPAM address range is configured to allow the particular domains host entries.

The following is the output of the script adding and deleting HOST records on an Infoblox in my lab.

Adding/Updating a HOST record

$ ibHOST.sh -u -h testing -i 172.16.1.254
D: "record:host/ZG5zLmhvc3QkLjEuY29tLnNweC5nbG9iYWwuZGUtdGVzdGluZw:testing.domain.contoso.com/Internal%20View"
U: "record:host/ZG5zLmhvc3QkLjEuY29tLnNweC5nbG9iYWwuZGUtdGVzdGluZw:testing.domain.contoso.com/Internal%20View"
 
$ host testing
testing.domain.contoso.com has address 172.16.1.254

Deleting a HOST record

$ ibHOST.sh -d -h testing
D: "record:host/ZG5zLmhvc3QkLjEuY29tLnNweC5nbG9iYWwuZGUtdGVzdGluZw:testing.domain.contoso.com/Internal%20View"
 
$ host testing
Host testing.domain.contoso.com not found: 3(NXDOMAIN)

This script has been very handy for most of my data center migrations. Using simple loop iteration to go through a list you can bulk add host records using the Infoblox WebAPI’s. This is not the best script to show off Infoblox WebAPI’s, but it gets the job done. If your looking to use this script, be very careful and test it before any mass runs! I take no responsibility if you damage anything in your environment.

Script

Just an FYI; this script is a modification of a previous post I did in 2012 that uses nsupdate to update A records on a bind server: Quickly update or delete a zonefile host entry.

#!/bin/bash
## Created By: deaves
# Quickly Add or Delete an Infoblox host entry.
#
## Requires: curl, WebAPI enabled on Infoblox.
 
DOMAIN="domain.contoso.com"
SERVER="infoblox.contoso.com"
DNSVIEW="Internal View"
USER="joeuser:joepass"
 
##### Begin Script #####
 
function DELETE () {
### DELETE HOST ###
 echo -n "D: "
 curl -k -u ${USER} -X DELETE https://${SERVER}/wapi/v1.0/`curl -k -u ${USER} -X GET https://${SERVER}/wapi/v1.0/record:host -d name=${HOST}.${DOMAIN} 2> /dev/null | grep "_ref" | head -n1 | awk -F\" '{print $4}'` 2> /dev/null
 echo
}
 
function ADD () {
### Update DNS record for HOST ###
 echo -n "U: "
 curl -k -u ${USER} -H "Content-Type: application/json" -X POST https://${SERVER}/wapi/v1.0/record:host -d "{ \"ipv4addrs\":[{\"configure_for_dhcp\": false,\"ipv4addr\": \"${IPv4}\"}],\"name\": \"${HOST}.${DOMAIN}\",\"view\": \"${DNSVIEW}\"}" 2> /dev/null
 echo
}
 
function usage () {
  ### Display the script arguments.
  printf "Usage: $0 [-du] -h  -i \n\n"
  printf "Requires one option!\n"
  printf "\t-d: Delete a \"${DOMAIN}\" HOST record\n"
  printf "\t-u: Update/Add a \"${DOMAIN}\" HOST record\n\n"
}
 
while getopts "duh:i:" ARG; do
  case "${ARG}" in
    d) [ -z $ACTION ] && { ACTION="D"; };;
    u) [ -z $ACTION ] && { ACTION="U"; };;
    h) HOST="$(echo $OPTARG | tr [:upper:] [:lower:])";;
    i) IPv4="$OPTARG";;
    ?) echo "Invalid option -$OPTARG"; exit 1;;
  esac
done 2> /dev/null
 
if [ "$ACTION" == "U" ]; then
  [ -z "$IPv4" ] && { echo "Error: Missing IP" && exit 1; }
  [ "$(host ${HOST}.${DOMAIN} | awk '{print $NF}')" != "3(NXDOMAIN)" ] && { DELETE ;}
  ADD
elif [ "$ACTION" == "D" ]; then
  [ -z "$HOST" ] && { echo "Error: Missing HOST" && exit 1; }
  [ "$(host ${HOST}.${DOMAIN} | awk '{print $NF}')" != "3(NXDOMAIN)" ] && { DELETE ;}
else
  usage && exit 1;
fi

Apparently there is no SNMP string to query to get the number of users associated to each of your SSIDs. So I created a small script to connect to the AP via its web interface and pull down an associated user count. Eventually I’ll create a cacti template for this script. In the meanwhile its just standalone script.

#!/bin/bash
## Created by: deaves
# Query an autonomous Cisco AP and display a count of all users associated to each SSID.
#
## Requires: curl
 
# Required script variables.
APHOST="10.0.0.2"            # AP hostname
AUTHUP="joeuser:joepassword"        # USERNAME:PASSWORD
 
# FUNCTION: End Script if error.
DIE() {
 echo "ERROR: Validate \"$_\" is installed and working on your system."
 exit 0
}
 
# Validate script requirements are meet.
type -p curl > /dev/null || DIE
 
 
printf "%-8s %-20s %-5s\n" "Radio" "SSID" "Users"
printf "%-8s %-20s %-5s\n" "=======" "===================" "====="
 
# Main Loop.
curl --user ${AUTHUP} http://${APHOST}/ap_assoc.shtml 2> /dev/null | awk 'sub(/\"htmlClients\"/,""){f=1} /^">/{f=0} f' | awk 'NR > 2' | while read LINE
 do eval ARRAY=( $LINE )
 
  [ "${ARRAY[0]}" == "802.11" -a "${ARRAY[4]}" == "Dot11Radio0:" ] && { RADIO="2.4GHz" ;}
  [ "${ARRAY[0]}" == "802.11" -a "${ARRAY[4]}" == "Dot11Radio1:" ] && { RADIO="5GHz" ;}
  [ "${ARRAY[0]}" == "SSID" ] && { SSID="${ARRAY[1]}"; echo; unset MAC ;}
  [ "${ARRAY[6]}" == "Assoc" ] && { MAC+=( "${ARRAY[0]}" ) ;}
 
  [ -n "${SSID}" -a -n "${ARRAY[0]}" ] && { printf "${RADIO} ${SSID} ${#MAC[@]} " ;}
 
 done | awk '{print $1,$2,$NF}' | sed '1d;s/\[//g;s/\] / /g' | while read RADIO SSID ASSOC
 do
 
  printf "%-8s %-20s %-5s\n" "${RADIO}" "${SSID}" "${ASSOC}"
 
 done

The following one-liner will create a new window for each /dev/ttyUSB port connected to the system. Assuming you’re in the dialout group. :)

 

for g in `groups`
 do [ "$g" == "dialout" ] &&
        {
          for TTY in /dev/ttyUSB*
           do TERM=`basename $TTY`
                screen -t "$TERM" $TTY 9600,-ixoff,-ixon || screen -s "$TERM"
           done
        }
done

 

03. December 2014 · Comments Off · Categories: Cisco, Networking

Normally they are to expensive for what they do, but the other day I found a HWIC-8A from ebay at a good price. As a result, I now have remote Serial & JTAG access to a bunch of test equipment via my Cisco Router. The following is a quick sample config I tossed together on how to configure it.

If needed the following is the pin-out to the Cisco Octal Cable: http://www.cisco.com/c/en/us/support/docs/dial-access/asynchronous-connections/14958-24.html

! Create a AAA authentication policy that will
! not make the user supply local credentials to
! connect to the Async TTY's. 
 
aaa new-model
aaa authentication login TERMSERV none
 
! Create an ACL to control who can connect.
! Warning: Anyone will be able to connect to the
! tty's when transport is configured.
 
ip access-list standard TERMSERV
 remark *** TERMSERV ACCESS ***
 permit 10.0.0.0 0.255.255.255
 permit 172.16.0.0 0.15.255.255
 permit 192.168.0.0 0.0.255.255
 
! Need to change the physical-layer to async
! Interface descriptions correspond to the
! CAB-HD8-ASYNC cable each port will represent.
 
interface Serial0/0/0
 physical-layer async
 description [0-3/0]
!
interface Serial0/0/1
 physical-layer async
 description [0-3/2]
!
interface Serial0/0/2
 physical-layer async
 description [0-3/4]
!
interface Serial0/0/3
 physical-layer async
 description [0-3/6]
!
interface Serial0/0/4
 physical-layer async
 description [4-7/0]
!
interface Serial0/0/5
 physical-layer async
 description [4-7/2]
!
interface Serial0/0/6
 physical-layer async
 description [4-7/4]
!
interface Serial0/0/7
 physical-layer async
 description [4-7/6]
 
! Set transport type and bind ACL/AAA to the Async lines.
 
line 0/0/0 0/0/7
 access-class TERMSERV in vrf-also
 login authentication TERMSERV
 transport input all
 transport output all
01. December 2014 · Comments Off · Categories: Linux, Linux Admin, OSX

I was recently playing around with MacOSX’s built-in dictation tools and had to convert a bunch of WMA files to a format that could be opened using Audacity.

The following one-liner uses a for loop to quickly convert each .WMA in the current working directory to a .MP3 file using avconv. If your using an older package repository avconv could be substituted for ffmpeg.

for FILE in *.WMA;
 do FILE=`echo $FILE | sed 's/.WMA//'`;
  avconv -i $FILE.WMA -acodec libmp3lame -ab 128k $FILE.mp3 ;
done

Remember: File names, including extensions, are case sensitive in Linux/Unix. Only files ending in “.WMA” will be iterated.