Starlight_0208 4f587b2cf5 主程序
更新了端口查询功能,后端console稍微修改了一下
2021-09-19 22:26:15 +08:00

51 lines
1.5 KiB
JavaScript

const express = require('express');
const { UnsupportedMediaType } = require('http-errors');
const app = express();
const port = 1234;
console.log("[Log] Server Starting up...");
app.use(express.json());
app.get("/api/IP", (req, res) => {
UserConnection = req.connection.remoteAddress
userIP = UserConnection.replace("::ffff:","");
Uport = req.connection.remotePort;
console.log(userIP)
if(req.query.type == 'json'){
if(req.query.port == 1){
var str = {"IP":userIP, "port":Uport, "Status":"OK"};
str_json = JSON.stringify(str);
res.send(str_json);
}else{
var str = {"IP":userIP, "Status":"OK"};
str_json = JSON.stringify(str);
res.send(str_json);
}
}else{
if(req.query.port == 1){
res.send(userIP + ":" + Uport);
}else{
res.send(userIP);
}
}
console.log("[Log]" + userIP + ":" + Uport + " Connecting to This Server.");
//pds
if(req.query.type == 'json'){
if(req.query.port == 1){
console.log("json: Y, Port: Y");
}else{
console.log("json: Y, Port: N");
}
}else{
if(req.query.port == 1){
console.log("json: N, Port: Y");
}else{
console.log("json: N, Port: N");
}
}
//res.send("Hello World");
res.end();
})
app.listen(port,() => {
console.log('[Log]Express server listening at http://localhost:' + port);
})