Question

Almost all of us have heard of services like spypig . I was wondering how do they track client's IP when an image from their server get loaded. To do the same I made an aspx page with Response.ContentType = "image/png" but for this my link goes as

www.something.com/imagePage.aspx?id=rndmval

Is there any method by which whenever an image from my server say "mysite.com/images/me.gif" gets loaded on a system i get notified with the ip of that system? Its similar to monitoring an image. I like the way spypig works, it can monitor an image whenever it gets loaded on any browser. Does anybody know how do they do that???

Était-ce utile?

La solution

You get the request, extract the IP address of the client from the request (not sure how to do that in ASP, but there certainly is a way to do that) and store it in a database / send an e-mail / whatever..

No need to set Content-type to image/png, it's just a nicer way to tell the browser, who is expecting an image, "here it is your image", but unless you return an actual 1x1 PNG image, it doesn't make much sense.

Update

The IP address should be contained in:

Request.ServerVariables("remote_addr")

If you want a "clean" url, such as http://example.com/path/to/image.gif, you have to do something webserver-side; one common hack used in PHP is to make the web server "rewrite" a request to /path/to/non-existent/file to something like /path/to/my/script.php?path=/path/to/non-existent/file, not sure how to do that with ASP/IIS though...

Update: How does spypig work

They give you an "image to be put in emails", that is, an <img> tag with a src="" pointing to some page on their server, containing a unique identifier in its name, for example:

http://example.com/track-user.asp?id=ABCD12345678

Once the user opens the email containing the image (beware that most email programs require the user to click "load external content" before images are actually loaded -- that is, an anti-tracking measure), a request is sent to the server which stores somewhere a record containing the id, date, ip address and any other interesting information.

Knowing who you sent a certain id to, you can track which is the e-mail that got opened.

(one common trick to get the user click on "load external images", is to send an e-mail that heavily require images to display properly, so the user is encouraged to load them -- and get tracked).

Autres conseils

Looking quickly at this spypig.com it seems that when you create an image it's given a unique ID. This ID is then stored in the database and when someone later enters this image, the system can match this unique ID with e-mail address that has to be notified.

Tracking IPs is actually much simpler. HTTP works on top of TCP/IP so you always know what is the address of the client (it might be a firewall/NAT/spoofed address though).

In ASP this might be useful: How to get a user's client IP address in ASP.NET? but virtually any HTTP server-side technology will give you access to this information. Look how much my web browser sends when loading an image (any e-mail client will provide similar information):

GET /rndmVal/img.gif HTTP/1.1
User-Agent: Opera/9.80 (X11; Linux i686; U; pl) Presto/2.10.229 Version/11.64
Host: localhost:8080
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: pl-PL,pl;q=0.9,en;q=0.8
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Connection: Keep-Alive

The IP address of client computer can be obtained from TCP/IP connection.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top