Search

I'll be at


My Twitter

    Subscribe

    Recent entries

    No recent entries.

    Archives by subject

    Archives by date

    Sun Mon Tue Wed Thu Fri Sat
        1 2 3 4 5
    6 7 8 9 10 11 12
    13 14 15 16 17 18 19
    20 21 22 23 24 25 26
    27 28 29 30 31    
    25
    Jan

    Finding open network sockets on Mac OSX

    I saw that there is a version of Leopard hanging around on the internet that can be used to run it on any Intel PC (well... an Intel PC with certain specifications!).

    To find out if the the proof indeed lies in the pudding, I started to download it via a torrent. Now, downloading a torrent that is over 2 gigs is not a simple task -- as least not here down in New Zealand, where bandwidth can be be at best described as quite sad.

    So my torrent download has now been going on for a day and a half, and I've been a good boy -- I've seeded more than downloaded :)

    However, I wanted to find out all the open network sockets so that I could possibly open up my firewall or tweak it somehow to increase the speed of downloads. So I needed to find out the all the open network sockets to see the port number.

    First I tried the usual netstat which gave me the following output:

    Proto Recv-Q Send-Q Local Address Foreign Address (state)
    tcp4 0 0 192.168.0.102.55129 74-46-59-218.dr0.13704 ESTABLISHED
    tcp4 0 0 192.168.0.102.55105 host66-227-dynam.53868 ESTABLISHED
    tcp4 0 0 192.168.0.102.54980 82.152.9.81.21695 ESTABLISHED
    tcp4 0 0 192.168.0.102.54723 73.167.217.87.dy.4630 ESTABLISHED
    tcp4 0 0 192.168.0.102.54418 163-158.static.q.http CLOSE_WAIT
    tcp4 0 34789 192.168.0.102.54397 71-80-169-111.dh.16262 ESTABLISHED
    tcp4 0 0 192.168.0.102.54387 213.22.163.110.6887 ESTABLISHED
    tcp4 0 0 192.168.0.102.54380 80.254.74.63.29113 ESTABLISHED
    tcp4 0 0 192.168.0.102.53414 20129006121.user.6881 ESTABLISHED
    tcp4 0 0 192.168.0.102.53183 adsl-76-248-156-.51413 ESTABLISHED
    tcp4 0 0 192.168.0.102.52146 cpe-24-162-115-1.53692 ESTABLISHED

    ... blah ...

    However the netstat out put does not show the process id and the name of actual name of the process.

    Then I found (thanks to the Man pages and Google), that there is a better way to do this -- lsof -i. This gives you an output like:

    i-n-d-i-v-e-r:~ indy$ sudo lsof -i
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    launchd 1 root 13u IPv6 0x3c2bbe8 0t0 TCP localhost:631 (LISTEN)
    launchd 1 root 14u IPv4 0x3f21e64 0t0 TCP localhost:631 (LISTEN)
    mDNSRespo 21 _mdnsresponder 7u IPv4 0x3c28b18 0t0 UDP *:5353
    mDNSRespo 21 _mdnsresponder 8u IPv6 0x3c28a40 0t0 UDP *:5353
    configd 27 root 8u IPv4 0x3c28cc8 0t0 UDP *:*
    configd 27 root 12u IPv6 0x45b8da0 0t0 ICMPV6 *:*
    mysqld 103 _mysql 10u IPv4 0x3f21a68 0t0 TCP *:3306 (LISTEN)
    ntpd 3903 root 20u IPv4 0x3c282a8 0t0 UDP *:123
    ntpd 3903 root 21u IPv6 0x3c28608 0t0 UDP *:123
    ntpd 3903 root 22u IPv6 0x3c28da0 0t0 UDP localhost:123
    ntpd 3903 root 23u IPv4 0x3c28968 0t0 UDP localhost:123
    ntpd 3903 root 24u IPv6 0x3c28890 0t0 UDP localhost:123
    ntpd 3903 root 25u IPv4 0x3c26a30 0t0 UDP 192.168.0.102:123
    ntpd 3903 root 27u IPv6 0x3c27b10 0t0 UDP i-n-d-i-v-e-r.local:123
    SystemUIS 4038 indy 9u IPv4 0x3c287b8 0t0 UDP *:*
    GrowlHelp 4047 indy 3u IPv4 0x4ea3a68 0t0 TCP 192.168.0.102:63110->216.64.142.80:80 (CLOSE_WAIT)
    Skype 4048 indy 6u IPv4 0x3c26370 0t0 UDP localhost:55598
    Skype 4048 indy 32u IPv4 0x3db9e64 0t0 TCP 192.168.0.102:51804->c211-30-0-59.wavrl1.nsw.optusnet.com.au:443 (ESTABLISHED)
    i-n-d-i-v-e-r:~ indy$ sudo lsof -i -P
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    launchd 1 root 13u IPv6 0x3c2bbe8 0t0 TCP localhost:631 (LISTEN)
    launchd 1 root 14u IPv4 0x3f21e64 0t0 TCP localhost:631 (LISTEN)
    mDNSRespo 21 _mdnsresponder 7u IPv4 0x3c28b18 0t0 UDP *:5353
    mDNSRespo 21 _mdnsresponder 8u IPv6 0x3c28a40 0t0 UDP *:5353
    configd 27 root 8u IPv4 0x3c28cc8 0t0 UDP *:*
    configd 27 root 12u IPv6 0x45b8da0 0t0 ICMPV6 *:*
    mysqld 103 _mysql 10u IPv4 0x3f21a68 0t0 TCP *:3306 (LISTEN)
    ntpd 3903 root 20u IPv4 0x3c282a8 0t0 UDP *:123
    ntpd 3903 root 21u IPv6 0x3c28608 0t0 UDP *:123
    ntpd 3903 root 22u IPv6 0x3c28da0 0t0 UDP localhost:123
    ntpd 3903 root 23u IPv4 0x3c28968 0t0 UDP localhost:123
    ntpd 3903 root 24u IPv6 0x3c28890 0t0 UDP localhost:123
    ntpd 3903 root 25u IPv4 0x3c26a30 0t0 UDP 192.168.0.102:123
    ntpd 3903 root 27u IPv6 0x3c27b10 0t0 UDP i-n-d-i-v-e-r.local:123
    SystemUIS 4038 indy 9u IPv4 0x3c287b8 0t0 UDP *:*
    GrowlHelp 4047 indy 3u IPv4 0x4ea3a68 0t0 TCP 192.168.0.102:63110->216.64.142.80:80 (CLOSE_WAIT)
    Skype 4048 indy 6u IPv4 0x3c26370 0t0 UDP localhost:55598
    Skype 4048 indy 32u IPv4 0x3db9e64 0t0 TCP 192.168.0.102:51804->c211-30-0-59.wavrl1.nsw.optusnet.com.au:443 (ESTABLISHED)
    Skype 4048 indy 33u IPv4 0x4281270 0t0 TCP 192.168.0.102:54418->163-158.static.quiettouch.com:80 (CLOSE_WAIT)
    Skype 4048 indy 35u IPv4 0x5f0166c 0t0 TCP *:24242 (LISTEN)
    Skype 4048 indy 36u IPv4 0x3c28530 0t0 UDP *:24242
    Skype 4048 indy 37u IPv4 0x44bb270 0t0 TCP 192.168.5.51:64396->ppp-58-8-80-254.revip2.asianet.co.th:443 (ESTABLISHED)
    Python 4446 indy 33u IPv4 0x3e32270 0t0 TCP *:6881 (LISTEN)
    Python 4446 indy 34u IPv4 0x3c25f38 0t0 UDP *:6881
    Python 4446 indy 37u IPv4 0x569c270 0t0 TCP 192.168.0.102:51831->dial8-20.infoave.net:11289 (ESTABLISHED)
    Python 4446 indy 41u IPv4 0x3db966c 0t0 TCP 192.168.0.102:53414->20129006121.user.veloxzone.com.br:6881 (ESTABLISHED)
    Python 4446 indy 44u IPv4 0x42dde64 0t0 TCP 192.168.0.102:55149->IGLD-83-130-215-156.inter.net.il:42017 (ESTABLISHED)
    Python 4446 indy 45u IPv4 0x5f01a68 0t0 TCP 192.168.0.102:54380->80-254-74-63.static.monzoon.net:29113 (ESTABLISHED)

    ... more here ...

    Using the lsof command (for listing open files), one can find out all the open files that are connecting to the network.

    Run it as sudo to give a list of all open files. If you don't, then you get a list of only those files that are open for the current users.

    Coming back to the original reason why I wanted to check the open connections, I could see all the ports that were being used by the torrent client. (I don't think I'll do anything to my firewall to "optimize" the connectivity. I'll just live with the slow download speed!)

     

    17
    Sep

    Setting Current JDK programmatically on Mac

    A few days back I was looking for a way to change the CurrentJDK symbolic link on my Mac. I had found this nice script somewhere (don't quite remember where). But is is very useful.

    #!/bin/sh

    cd /System/Library/Frameworks/JavaVM.framework/Versions

    CURJDK="`readlink CurrentJDK`"
    echo Current JDK version: $CURJDK

    if [ "$1" == "" ]; then
    echo Installed versions:
    ls
    exit
    fi

    VERFOUND=`ls | grep $1 | head -n 1`

    if [ "$VERFOUND" != "$1" ]; then
    BASE="`basename $0`"
    echo Error: Could not change JDK-- version $1 not installed!
    echo Run $BASE without arguments to see a list of installed versions.
    exit 127
    fi

    echo You must now enter your Mac OS X password to change the JDK.
    sudo ln -fhsv $1 CurrentJDK

    Save it as a file name of your choice. I saved it as "SetJDK.sh". Give it execute permissions, and run the script.

    5
    Sep

    Adding the PATH variable on Mac OSX

    This is another one of those blog entries where I want to blog for the sake of remembering tedious details...

    The issue that I was facing was how to add a directory to the PATH environment variable on my Mac.

    I wanted to add a path to MySQL install. So I'll use that example. The following command in a Terminal window created my .bash_profile file. If the file already exists, it would have added to that file.

    echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

    The PATH information is stored in /Users/username/.bash_profile file.

    4
    Sep

    Finding and configuring JAVA_HOME on Mac OSX

    Just so that I don't forget...

    While installing JBoss, I found that I need to setup my JAVA_HOME variable correctly.

    After checking a couple of sites, I found the following to be a good way to figure out and setup JAVA_HOME variable on Mac OSX.

    In a Terminal window, type

    which java

    This pointed to "/usr/bin/java", which was a symbolic link to "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Commands/java". This in turn was a symbolic link to "/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2".

    So my JAVA_HOME was pointing to "/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home".

    In order to change the JAVA_HOME variable I found a very nice utility called "RCEnvironment" that let me setup all kind of environment variables, including JAVA_HOME, very nicely and easily.

    Once I added a JAVA_HOME variable (and pointed it to Java 5 home using RCEnviornment, I logged out and back in again. My JAVA_HOME was setup as I wanted.

    2
    Feb

    Hello Ubuntu! I'm going easy on Vista

    Today I had an interesting conversation with colleagues and friends about Vista and who all amongst us wanted to upgrade our home computers to Vista.

    All of them said they were going to hold off upgrading their home machines. There seemed to be a few valid reasons:

    » Continue reading "Hello Ubuntu! I'm going easy on Vista"