Archive for the ‘Programming’ Category

Official Phish.net Google Chrome Extension

Here is the release announcement for the Official Phish.net Google Chrome extension that myself and Adam Scheinberg have been working on.

We’re proud to unveil the official Phish.net Google Chrome extension. Written by user Terry Moore and blessed by the Phish.net tech team, this extension utilizes Phish.net API goodness to deliver setlists and forum posts right into your browser.

via Phish.net

Reddit Hover Craft: My Google Chrome Extension

I wrote my first Google Chrome Extension, Reddit Hover Craft.  This extension will popupimages posted to Reddit.com in a jQuery pop window.  This allows for a smoother Reddit browsing experience because you dont have to navigate away from Reddit to view all the pictures posted to imgur.com.

Motersho’s GeoIP Lookup

I got bored the other day and decided that I wanted a page that I could query via a bash script and it would tell me my public IP address. Yes I know there are plenty of site that have this but I wanted my own.

Here is the lookup page: http://motersho.com/blog/index.php/geoip-lookup/

Well that idea then manifested itself to a place where I can get City, State, Country and Longitude/Latititude coordiates of that IP address. So, I wrote two pages one that uses the MaxMind API and thier Free IP to City database and the other uses HostIP’s API and their database to do Geo lookups and using the Google Maps API for maping that location.

The HostIP database is not as complete as the as MaxMind‘s so they as that if you come across an unknown address you help them out by updating that info. Please help them out.

My site still has the ability to to just return your public IP address for scripting, you just have to pass it the correct parameter.

For scripting: http://motersho.com/ip/?o

Here is the code to return you public IP in a bash script

curl http://motersho.com/ip/?o

Leave me a comment if you use this site in a script or if you have found it useful in any other way.

Writing Traceroute in Python

Ksplice.com has put together a tutorial on how to write the traceroute/tracert application in Python in just 8 easy steps.  This is a good introduction on how the traceroute application works and socket programming in Python.

Here is the finished product but please read thier post to see all of the steps.

#!/usr/bin/python
 
    import socket
 
    def main(dest_name):
        dest_addr = socket.gethostbyname(dest_name)
        port = 33434
        max_hops = 30
        icmp = socket.getprotobyname('icmp')
        udp = socket.getprotobyname('udp')
        ttl = 1
        while True:
            recv_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
            send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp)
            send_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
            recv_socket.bind(("", port))
            send_socket.sendto("", (dest_name, port))
            curr_addr = None
            curr_name = None
            try:
                _, curr_addr = recv_socket.recvfrom(512)
                curr_addr = curr_addr[0]
                try:
                    curr_name = socket.gethostbyaddr(curr_addr)[0]
                except socket.error:
                    curr_name = curr_addr
            except socket.error:
                pass
            finally:
                send_socket.close()
                recv_socket.close()
 
            if curr_addr is not None:
                curr_host = "%s (%s)" % (curr_name, curr_addr)
            else:
                curr_host = "*"
            print "%d\t%s" % (ttl, curr_host)
 
            ttl += 1
            if curr_addr == dest_addr or ttl > max_hops:
                break
 
    if __name__ == "__main__":
        main('google.com')

First Python Program

I have been off and on trying to learn Python for a few months now and yesterday I successfully finished my first real application. Unfortunately it was for work and I cannot post the source code for you all to tear a part. But it was an application displayed a menu that allowed the user to choose and made several Oracle database calls using the module cx_Oracle to test some functionality of my companies application.

There was that vague enough?

To make it useful I had to use the py2exe application to make it into a Windows executable. I had to step down my version of Python from 2.6 to 2.4 to get the py2exe compiled python application to work due to the version of C++ that Python 2.4 and 2.6 are compiled with.

I hope to start making some useful applications in the near future where I can post the source code and you all comment on and tear apart.

View Oracle dbms_output with Python

After doing lots of searching on the Internet for how to get the dbms_output from an Oracle SQL query with Python I finally found something.

import cx_Oracle
 
conn = cx_Oracle.Connection("userid/password@tns")
curs = conn.cursor()
curs.callproc("dbms_output.enable")
 
sqlCode = """
some long
sql code 
with dbms_output
"""
 
curs.execute(sqlCode)
 
statusVar = curs.var(cx_Oracle.NUMBER)
lineVar = curs.var(cx_Oracle.STRING)
while True:
  curs.callproc("dbms_output.get_line", (lineVar, statusVar))
  if statusVar.getvalue() != 0:
    break
  print lineVar.getvalue()