Tuesday, September 28, 2010

Netstat 101

We all know netstat which can show you all the important network connections - if you remember how to use it. I always forget and it's hard to find it again. So I'll post the commands I found most useful in here.

This command displays all active TCP connections:
netstat --tcp --programs --numeric-ports
netstat -tp --numeric-ports (shorter)
Aktive Internetverbindungen (ohne Server)
Proto Recv-Q Send-Q Local Address   Foreign Address State      PID/Program name
tcp        0      0 localhost:3306  localhost:38525 VERBUNDEN  3024/mysqld
tcp        0      0 localhost:3306  localhost:38527 VERBUNDEN  3024/mysqld
tcp       38      0 picard:36800    ldap.****       CLOSE_WAIT 1146/dbus-daemon

Parameter --programs adds the program name info, --numeric-ports prevents netstat of hiding the port numbers. To display UDP connections use --udp.

netstat --tcp --listening --programs --numeric-ports
netstat -tlp --numeric-ports (shorter)
Aktive Internetverbindungen (Nur Server)
Proto Recv-Q Send-Q Local Address  Foreign Address  State   PID/Program name
tcp        0      0 *:3306         *:*              LISTEN  3024/mysqld
tcp        0      0 *:22           *:*              LISTEN  2630/sshd
tcp        0      0 *:8080         *:*              LISTEN  12439/java

If you want to have the output continuously refreshed use "watch -n1". And if you've got a netstat that displays the information partially in another language (german in my case) you can set the locale to have it all in english. That will make using grep so much easier...

LANG=en watch -n1 netstat -tlp --numeric-ports

Some of the examples in here were copied from http://www.linuxhowtos.org/Network/netstat.htm .

Wednesday, August 18, 2010

GWT panel for HTML UL/LI lists

For my current GWT projects I wanted to make more use of HTML UL/LI elements than the table based layouts that you normally use in GWT applications. Biggest advantages for me is that other people can make changes to the layout/design of the page without having to touch the code itself.

I couldn't find a class in GWT or anywhere else that helps with that, so I wrote my own. I can create HTML like this now:

  • Widget A
  • Widget B
with this code:
UlListPanel ulList = new UlListPanel();

Download here: UlListPanel.java
The code is a bit messy, so if you have a better version let me know.

I'm using this class for my GWT based travel blog software.

Friday, June 4, 2010

Automated String Escaping in Eclipse

When having to paste text into a String in Eclipse which includes quotes, line breaks etc. nearly everyone does it manually. However, Eclipse actually comes with a feature which does this automatically for you. But for some weird reason it turned off.

You can turn it on under Window / Preferences / Java / Editor / Typing / Escape text when pasting into string literal.

Tuesday, June 1, 2010

Simple XML Writer / Indenter

Recently, I was again looking for an easy way to generate a few lines of nicely formatted XML. I don't want to use a fat XML library and a serialization process for this simple task. Since I couldn't find a suitable solution so I wrote it myself.

For instance, with the following piece of code:
XmlWriter xml = new XmlWriter();
xml.beginElement("GeoData", "xmlns='http://geo.net/data'");


you get this:
<?xml version="1.0" encoding="UTF-8"?>


Quite straightforward. Its like a simliar class we where using at work. Not having dependencies on big XML libraries also means you can use it in GWT applications where no such dependencies are allowed. I'm using this class for my GWT based travel blog.

You can download it here:
- XmlWriter.java
- XmlWriterTest.java

If its useful for you, write a comment.