I want to write a script to find the latest version of rpm of a given package available from a mirror for eg: mirror.centos.org/centos/5/os/x86_64/CentOS/

The script should be able to run on majority of linux flavors (eg centos, redhat, ubuntu). So yum based solution is not an option. Is there any existing script that does this? Or can someone give me a general idea on how to go about this?