views:

257

answers:

5

I get a file url,for example, http://cidian.youdao.com/download/YoudaoDict.exe

how can I get it's version but not download it ?

nots 1: if you download the file first on your computer,there are many ways to get it's

version, for example ,you can use the window tools "filever.exe" to get the version.

but i want to not download it ,at least not download it all.how can I do? Waiting your

help! thanks.

nots 2: I have tried the way to get a portion of the file to get the version:

first, I used the download tool "wget.exe" to download a portion of the file ( wget.exe is

a single-threaded download tool,it can make sure download form the head)

second, I used the "filever.exe" to get the file version.

In this way, some software i can get it's version,but some cann't(they must all be

downloaded).I don't know why.

+3  A: 

Version numbers, if any, are embedded in the .exe file itself. You will have to download at least a portion of the file to retrieve these bits of metadata.

Check out the .exe file format spec.

Oren Trutner
I have tried the way to get a portion of the file to get the version:first, I used the download tool "wget.exe" to download a portion of the file ( wget.exe is a single-threaded download tool,it can make sure download form the head)second, I used the "filever.exe" to get the file version.In this way, some software i can get it's version,but some cann't(they must all be downloaded).I don't know why.
li
+1  A: 

Well in theory this is the kind of task that an HTTP HEAD request is designed for but iirc the only relevant info you'd get by default (if the request was handled at all of course) would be Content-Length and Last-Modified. Edit: and ETag!

That probably gets you much of what you need to know, but if you really wanted to have version number you'd have to be in control of the web service and be able to obtain and append that information to the response headers. Not so hard to do but only if you have control of the service.

annakata
+3  A: 

You can do an HTTP HEAD request, and the server may report the size of the item in Content-Length. It may also report a version under the Last-Modified header. Further, ETag may be present for the same purpose.

You can test this with netcat:

> nc cidian.youdao.com 80
HEAD /download/YoudaoDict.exe HTTP/1.1
Host: cidian.youdao.com

HTTP/1.1 200 OK
Date: Mon, 10 Aug 2009 06:11:59 GMT
Server: Apache
ETag: "Dcm1w6Vxg51"
Last-Modified: Sat, 08 Aug 2009 02:18:40 GMT
Accept-Ranges: bytes
Content-Length: 4820792
X-Request-Received: t=1249884719506801
X-Request-Processing-Time: D=906244
Content-Type: application/octet-stream

As you can see, in your example case, all three headers are given, so you can guess version changes based on that information. I'd always check to insure Date and Last-Modified aren't the same, as sometimes the latter is set to the former for pages generated by scripts.

Conspicuous Compiler
+4  A: 

I notice that that particular exe link supports byte range requests.

$ curl -I http://cidian.youdao.com/download/YoudaoDict.exe
HTTP/1.1 200 OK
...
Accept-Ranges: bytes
Content-Length: 4820792
...
Content-Type: application/octet-stream

You could make one or more HTTP byte range request to get the parts of the file you need to determine the version. You'd just be making several requests to get the parts of the file you'd look at if it were on your hard drive.

For example, based on the HTTP/1.1 spec, you can request the first 500 bytes with this request header:

curl -H"Range: bytes=0-499" http://... -o bytes-0-499.dat
Harold L
"You could make one or more HTTP byte range request to get the parts of the file you need to determine the version. "how can I used parts of the file to determine the version? Can you tell more ?
li
Since you're using filever.exe, part of Windows, you're looking at the DLL version set in the binary format for a DLL/EXE file. My first try would be to download about 4k (-H"Range: 0-4095") and try running filever.exe on that part of the file. Reason: the version is probably part of the header at the beginning of the EXE file.
Harold L
but if you try this, http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exeit will fail,it cann't get it's version until you download it all.do you know why?
li
+1  A: 

If your purpose is to detect when a new version becomes available, you could look at the response of a HEAD HTTP request as others have suggested.

Otherwise, you could screen scrape the (download page) and extract the latest version details. There is a convenient <dl id="downloadSth"> tag within which version info is listed and could conceivably be harvested. I have no idea whether this is going to be reliable; the site's authors could change this without notice.

I'd look at using BeautifulSoup for this.

mhawke