Created
January 19, 2016 18:08
-
-
Save APTy/1106c6fb7bd692422c38 to your computer and use it in GitHub Desktop.
Image to get IP Address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var server = require('http').createServer(); | |
var httpPng; | |
const HTTP_STATUS_OK = 200; | |
const PNG_FILE_NAME = 'http.png'; | |
const PNG_HEADER = {'Content-Type': 'image/png'}; | |
// Load the file into memory | |
fs.readFile(PNG_FILE_NAME, function(err, data) { | |
if (err) throw err; | |
httpPng = data; | |
}); | |
server.on('request', function(req, res) { | |
// Save the requester's address | |
fs.appendFile('ips.txt', req.client.address().address + '\n'); | |
// Serve the image | |
if (req.url.indexOf(PNG_FILE_NAME) !== -1) { | |
res.writeHead(HTTP_STATUS_OK, PNG_HEADER); | |
res.write(httpPng); | |
} | |
// End the response | |
res.end(); | |
}); | |
server.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment