Thursday, July 05, 2007

Which XP ports are open?

Don't know how many times I see the message "Error - port 8080 already in use" or some such.

So how do you find whose using that port. One answer is netstat which runs in a cmd window:


Displays protocol statistics and current TCP/IP network connections.

NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]

-a Displays all connections and listening ports.
-b Displays the executable involved in creating each connection or
listening port. In some cases well-known executables host
multiple independent components, and in these cases the
sequence of components involved in creating the connection
or listening port is displayed. In this case the executable
name is in [] at the bottom, on top is the component it called,
and so forth until TCP/IP was reached. Note that this option
can be time-consuming and will fail unless you have sufficient
permissions.
-e Displays Ethernet statistics. This may be combined with the -s
option.
-n Displays addresses and port numbers in numerical form.
-o Displays the owning process ID associated with each connection.
-p proto Shows connections for the protocol specified by proto; proto
may be any of: TCP, UDP, TCPv6, or UDPv6. If used with the -s
option to display per-protocol statistics, proto may be any of:
IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.
-r Displays the routing table.
-s Displays per-protocol statistics. By default, statistics are
shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6;
the -p option may be used to specify a subset of the default.
-v When used in conjunction with -b, will display sequence of
components involved in creating the connection or listening
port for all executables.
interval Redisplays selected statistics, pausing interval seconds
between each display. Press CTRL+C to stop redisplaying
statistics. If omitted, netstat will print the current
configuration information once.



so netstat -ano gives



Active Connections

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:86 0.0.0.0:0 LISTENING 728
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 1192
TCP 0.0.0.0:261 0.0.0.0:0 LISTENING 3684
...





You can look up the PID using Task Manager or (even better) using sysinternals Process Explorer (which you can get from here).

Their version of netstat is TCPView (which you can get from here).

Enjoy!

Friday, June 01, 2007

Unix : DOS format on a Unix box

Quite often I use an IDE on Windows to edit the file and then FTP the file to a Linux box. (Mainly because vi sucks major league, big time!)

Anyway, the Unix compiler sometimes complains about rogue characters. An easy way to fix this is to use the

dos2unix

utility which reads the text file and converts to Unix format.

Enjoy!

ASP : Using LiveHTTPHeaders to monitor what's being sent

Quite often, you need to see what a web site is sending from the ASP pages. You could use something like Ethereal but if you are a Firefox fan, an easy way is to use LiveHTTPHeaders.

You can get the LiveHTTPHeaders Firefox extension from here.

Then install it.

Click Firefox Tools / LiveHTTPHeaders.

If you want to limit the URL's that are monitored and you are a dab hand at regular expressions, then click Config tab / Filter URL's with regexp

Close the Config tab

From the Firefox menu, click Select View / Sidebar / LiveHTTPHeaders (or alternatively click Alt L)

Open a page from the website you wish to monitor. What is displayed is what is being sent to the server.

Enjoy!

Tuesday, May 01, 2007

Another reading list

Came across this reading list here.

This one comes from John Brewer.

Enjoy!

ASP : Getting configuration variables from web.config

Instead of hard-coding these in the .cs code, you could use the following:

string inputFile = ConfigurationManager.AppSettings.Get("FileLoc");

In the web.config, in the appSettings section, enter something like:

LSBadd key="FileLoc" value="C:\somewhere\File.xml" /RSB

where:

LSB = Left square bracket
RSB = Right square bracket

You can also do this from Visual Studio when viewing an .aspx page. Click Website / ASP.NET configuration and type in the entries there.

Enjoy!

ASP : Creating Javascript on the server side

Javascript is normally created in the HTML file but it can be created on the server side.

e.g. the script to open another window could be:


string exampleScript =
"LSBscript language='javascript'RSB\n" +
"window.open ('http://some url', '_blank', " +
"'scrollbars=yes,resizable=yes,status=yes" +
",toolbar=no,menubar=yes,location=no" +
",width=screen.availWidth" +
",height=screen.availHeight" +
",screenX=0,screenY=0,top=0,left=0');\n" +
"LSB/scriptRSB";

ClientScript.RegisterStartupScript(typeof(Page), "ExampleScript", exampleScript);


where:

LSB = Left square bracket
RSB = Right square bracket

Enjoy!

C# : Creating dates

The simplest way is to use:


string thisDate = "1990-01-01";
DateTime datetime = DateTime.Parse (thisDate);


Enjoy!

Friday, April 27, 2007

Recommended reading for developers

Another list from "Coding Horror" - programming and human factors by Jeff Atwood.

Blog here.

Reading list here.

Enjoy!

Thursday, April 19, 2007

ASP : Deploying web site from Visual Studio 5

From the ASP solution,

File / Add / New Project / Setup and Deployment / Web Setup Project

Type in a name and enter "OK".

The entry will now be in "Solution Explorer". Right-click and select "Add / Project Output". Ensure "Content Files" is selected and click "OK".

Now we want to build it. Right-click again and select build. This will create the .msi file in the directory.

Enjoy!

SOAP : Asynchronous web service

Had to implement an asynchronous web service which did not need to be real-time so no response was needed.

Had me a bit puzzled until I realised that a web service can return void!

i.e. in ASP:

[WebMethod]
public void webMethod(Some parameter)

compiles and runs no problem.

So what does it return?

The WSDL shows:


s:element name="webMethodResponse"
s:complexType /
/s:element


So it actually returns null!

Enjoy!

Wednesday, April 11, 2007

Windows : Getting a file list

Often need to put a list of files into a Word document or some such.

One way is to activate the command prompt (DOS box), navigate to the required directory and type:

dir /ON /B > dir.txt

The /ON option lists the files in alphabetic order. Further options are:


/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order


The /B option uses a bare format (i.e. no heading information or summary).

The pipe option (>) sends the results to a file called dir.txt in the current directory.

From here, it can be cut & pasted into the Word document.

BTW, if you ever need to get information about a DOS command, type:

help "command"

e.g. help dir

Enjoy!

Unix : sum

Often transfer large files around using FTP or whatever e.g. ear and war files and it's useful to see if they were transferred without error.

sum is a useful utility to use for this.

It calculates and prints a 16-bit checksum for the named file and the number of 512-byte blocks in the file.


sum abcd.ear
05612 25680


Enjoy!