-
Notifications
You must be signed in to change notification settings - Fork 4
/
web.js
31 lines (26 loc) · 1.18 KB
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require('express')
const app = express()
var http = require('http');
app.get('/', function(request, response){
var getClientAddress = function (req) {
return (req.headers['x-forwarded-for'] || '').split(',')[0]
|| req.connection.remoteAddress;
};
response.send(getClientAddress(request));
});
app.get('/api/ipaddress.json', function(request, response){
var getClientAddress = function (req) {
return (req.headers['x-forwarded-for'] || '').split(',')[0]
|| req.connection.remoteAddress;
};
// response.send(getClientAddress(request));
response.json({userAgent:request.headers['user-agent'],method:request.method,fresh:request.fresh,xhr:request.xhr,protocol:request.protocol,ipAddress:getClientAddress(request),remoteAddress:request.connection.remoteAddress,forwarded:request.headers['x-forwarded-for']});
});
// Using built-in http library and public API from https://www.ipify.org/
http.get({'host': 'api.ipify.org', 'port': 80, 'path': '/'}, function(resp) {
resp.on('data', function(ip) {
console.log("My public IP address is: " + ip);
});
});
var port = process.env.PORT || 3000;
app.listen(port, () => console.log("Listening on " + port))