Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const myScanner = require('./myScanner.js');
- const ipGeolocation = require('./ipGeolocation');;
- var app = express();
- app.use(function(req, res, next) {
- res.header("Access-Control-Allow-Origin", '*');
- res.header("Access-Control-Allow-Credentials", true);
- res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
- res.header("Access-Control-Allow-Headers", 'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json');
- next();
- });
- const port = process.env.PORT || 3000;
- app.get('/', (req, res) => {
- res.send('<h2>server is up</h2><br><strong>GET</strong> /api/port/:ipAddr<br><strong>GET</strong> /api/geo/:ipAddr');
- });
- app.get('/api/port/:ipAddr', (req, res) => {
- const ip = req.params.ipAddr;
- myScanner.portScan(ip)
- .then((list) => {
- res.send(list);
- }).catch((err) => {
- res.status(400).send(err); //invalid ip address
- });
- });
- app.get('/api/geo/:ipAddr', (req, res) => {
- const ip = req.params.ipAddr;
- ipGeolocation.locate(ip)
- .then((info) => {
- res.send(info);
- }).catch((err) => {
- res.status(400).send(err); //invalid ip address
- });
- });
- app.listen(port, () => {
- var time = new Date().toString();
- console.log(`[${time}] Server in up on ${port}`);
- });
Add Comment
Please, Sign In to add comment