123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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);
- })
|