preload
Sep 13

When I’m writing iRules programs on my MacBook Pro as part of my job at F5 Networks, I like to copy in configuration and setup information as part of documenting the program.  This entails cutting and pasting in multi-line config file sections and then adding the ‘#’ comment character to the start of each line.  Well, after doing that a couple of times, I knew there was a way to automate that.  Enter some Applescript:

(*  Comment/Uncomment Block
    Add & remove '# ' in Selection. Good for iRules comments.
	Assign to a key for best use.

	John Allen, F5 Networks
	Sept. 12, 2011
*)

tell application "BBEdit"
	activate
	repeat with x in lines of selection of window 1 of text document 1
		if exists character 1 of text of x then
			set start to character 1 of text of x as text
		else
			set start to ""
		end if
		if start is not "#" then
			replace "^" using "# " searching in text of x options {search mode:grep}
		else
			replace "^# " using "" searching in text of x options {search mode:grep}
		end if
	end repeat
end tell

Of course, you can modify this to work with any programming language.

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Aug 22

When I went to do a restore of my locked up iPhone (Thank you iOS 4.3.5 update), I plugged it in and it asked for a password before it could do the restore. Password?? I don’t remember putting any password on my backup?!?   Doing a quick google turns up a bunch of people looking for help, with lots of other people telling them they shouldn’t steal ;)

After trying a number of different passwords, I finally made the connections:  Its the password of your computer login Id you are logged in as.  Not any security PIN, not your AppleID password.

Hope that helps someone! :D

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Jun 03

Recently I decided that I needed a copy of an ‘fport’ program for Windows that would let me see what program was making connections out of my computer. Unfortunately, my Anti-Virus software warned me that the website where it is posted was on the known virus websites list, so I just decided to make my own.

I started looking around for a programatic way to do what the normal ‘netstat’ program does, but everything I found was rather involved…and since I didn’t want to spend a whole lot of time on it, I cheated and just used the output from the ‘netstat -ano’ command and then did a quick lookup of the returned PID to find the program.

The result is the following code: Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Apr 13

This is a follow-on to my Python Connectivity Check Script that I posted a while back. It functions the same way…its just written in Perl. I use both program as part of a System Connectivity Check program I wrote in Ruby to connect to many hosts, upload one of these connectivity check programs, run it and place the results into an Excel spreadsheet with a simple red/green status. When you are installing systems with hundreds of nodes that all need to talk to 30-odd other nodes, its a huge time saver!

Here’s the code: Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Mar 07

While doing a quick search for Ruby code that could catch and print out the Beacon packet that Tivo machines send out on the local network, I was shocked to not find anything….tons of stuff in Perl….but nothing Ruby! Unbelievable! So I went and figured out what the code would be in Ruby. Here’s what I got:

require 'socket'
require 'exo/xdump'

trap("INT") do
   puts "---[Ctrl-C: Exiting]---\n\n"
   Kernel.exit(0)
end

BasicSocket.do_not_reverse_lookup = true
s = UDPSocket.new
s.bind("0.0.0.0", 2190)

loop do
   flg = IO.select([s], nil, nil, 5)
   if flg
      text, sender = s.recvfrom_nonblock(1024)
      puts "[#{Time.now}] #{sender[3]} sent beacon packet:"
      puts "[#{Time.now}]\n#{text.hexdump}"
   end
end

Nothing too fancy. The beacon is sent out as a UDP packet to port 2190. The code looks for data on the socket, then retrieves the the data and prints it out in a hex dump format like so:

[Sun Mar 07 20:37:53 -0800 2010] 10.11.12.52 sent beacon packet:
[Sun Mar 07 20:37:53 -0800 2010]
000000: 7469 766f 636f 6e6e   6563 743d 310a 7377 |tivoconnect=1.sw|
000010: 7665 7273 696f 6e3d   392e 332e 3262 2d30 |version=9.3.2b-0|
000020: 312d 322d 3134 300a   6d65 7468 6f64 3d62 |1-2-140.method=b|
000030: 726f 6164 6361 7374   0a69 6465 6e74 6974 |roadcast.identit|
000040: 793d 3234 3030 3030   30Xx XxXx XxXx XxXx |y=2400000XXXXXXX|
000050: Xx0a 6d61 6368 696e   653d XxXx XxXx XxXx |X.machine=XXXXXX|
000060: 0a70 6c61 7466 6f72   6d3d 7463 642f 5365 |.platform=tcd/Se|
000070: 7269 6573 320a 7365   7276 6963 6573 3d54 |ries2.services=T|
000080: 6956 6f4d 6564 6961   5365 7276 6572 3a38 |iVoMediaServer:8|
000090: 302f 6874 7470 0000   0000 0000 0000 0000 |0/http.         |

The identity and the machine values have been changed just to be safe :)

A big issue that a lot of folks have with UDP sockets in Ruby is trying to get a non-blocking read working correctly. The use of the IO.select above seems to be the best answer that I’ve seen…but its still not perfect. Some folks have been trying out eventmachine (See the “Non-Blocking UDP” thread over on Ruby Forum), but for this simple test, the IO.select should work just fine.

I covered the hexdump function in a previous post.

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Feb 10

Anyone who has ever worked with networks at one point or another always ends up running a telnet or ping command over and over again to generate traffic and check if one computer can talk to another. After running that command a couple dozen times, one starts to think that maybe it would be better to write a program to do this instead.

One of my customers has a number of RedHat servers that I’m not allowed to install any programing language like Ruby or Perl on that I would normally use to write such a program…however, they have a complete Python installation for some reason. Not to argue with fate, I wrote the following script to run my tests with:

#
# nettest.py
#
import sys
import socket
import time

host = sys.argv[1]
port = int(sys.argv[2])
# type => ["tcp" or "udp"]
type = sys.argv[3]
test = ""
if len(sys.argv) > 4 :
 test = sys.argv[4]

while 1 :
  if type == "udp":
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  else:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.settimeout(5)
  try:
    if type == "udp":
      s.sendto("--TEST LINE--", (host, port))
      recv, svr = s.recvfrom(255)
      s.shutdown(2)
      print "Success connecting to " + host + " on UDP port: " + str(port)
    else:
      s.connect((host, port))
      s.shutdown(2)
      print "Success connecting to " + host + " on TCP port: " + str(port)
  except Exception, e:
    try:
      errno, errtxt = e
    except ValueError:
      print "Cannot connect to " + host + " on port: " + str(port)
    else:
      if errno == 107:
        print "Success connecting to " + host + " on UDP port: " + str(port)
      else:
        print "Cannot connect to " + host + " on port: " + str(port)
        print e
  if test != "C" :
    sys.exit(0)

  s.close
  time.sleep(1)

This is run like so: Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with:
Jan 28

One of my customers has these Cisco 4900M Switches and we had to figure out what the baud rate/stop bits/parity settings were. In the hopes that this one day helps some other Cisco IOS newbie, here’s how you find it:

Log into the switch, and at the command prompt, enter this command:

show line con 0

You should see something similar to this:
Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: