An overview of the method is given in the document "Automatic Correction of Lens Distortion by Using Digital Image Processing" (pdf), which is also included in the zip-file below.
The software is available for Matlab. It can be downloaded from the following links:
For installation information see the documentation included in the zip-file (file undistort.html).