app.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const express = require('express');
  2. const { UnsupportedMediaType } = require('http-errors');
  3. const app = express();
  4. const port = 1234;
  5. console.log("[Log] Server Starting up...");
  6. app.use(express.json());
  7. app.get("/api/IP", (req, res) => {
  8. UserConnection = req.connection.remoteAddress
  9. userIP = UserConnection.replace("::ffff:","");
  10. Uport = req.connection.remotePort;
  11. console.log(userIP)
  12. if(req.query.type == 'json'){
  13. if(req.query.port == 1){
  14. var str = {"IP":userIP, "port":Uport, "Status":"OK"};
  15. str_json = JSON.stringify(str);
  16. res.send(str_json);
  17. }else{
  18. var str = {"IP":userIP, "Status":"OK"};
  19. str_json = JSON.stringify(str);
  20. res.send(str_json);
  21. }
  22. }else{
  23. if(req.query.port == 1){
  24. res.send(userIP + ":" + Uport);
  25. }else{
  26. res.send(userIP);
  27. }
  28. }
  29. console.log("[Log]" + userIP + ":" + Uport + " Connecting to This Server.");
  30. //pds
  31. if(req.query.type == 'json'){
  32. if(req.query.port == 1){
  33. console.log("json: Y, Port: Y");
  34. }else{
  35. console.log("json: Y, Port: N");
  36. }
  37. }else{
  38. if(req.query.port == 1){
  39. console.log("json: N, Port: Y");
  40. }else{
  41. console.log("json: N, Port: N");
  42. }
  43. }
  44. //res.send("Hello World");
  45. res.end();
  46. })
  47. app.listen(port,() => {
  48. console.log('[Log]Express server listening at http://localhost:' + port);
  49. })