GithubHelp home page GithubHelp logo

coreybutler / porthog Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 8.0 422 KB

Identify which process is using a specific port.

License: MIT License

JavaScript 100.00%
port management portscanner detection conflict port-conflict

porthog's Introduction

porthog

This module identifies which application is using a specified port, providing the process name and PID. Works for Windows, OSX, and most flavors of Linux/Unix that support the lsof, ss, or netstat operations.

Windows, macOS, & Linux

CLI Implementation

npm install -g porthog

porthog 33649 80

Outputs:

PORT      PID       PROCESS
--------------------------------------------------
33649     43580     node-webkit Helper (cbutler)
80        -         -

API Implementation Example

const porthog = require('porthog')
const data = porthog(80)

console.log(data.user, 'is running', data.process + ' (PID ' + data.pid + ') on port 80.')

// Output
// cbutler is running node.exe (PID 656) on port 80.

This operation may require elevated/root privileges.

Uses

We're using this in Fenix Web Server to resolve port conflicts. When a user tries to launch a server on an occupied port, we use porthog to determine which app is "hogging" the port and provide the user an option to stop/kill the offending process.

We also use this in combination with node-windows, node-mac, and node-linux to create background processes that monitor ports and notify users what's running on the ports they want to use.

There are certainly many other uses. If you use this, be warned that some operating systems (Windows in particular) may require elevated permissions. This is dependent on each user's environment, so it's not always predictable. To get around this, we've found the aforementioned node-* modules to be useful when creating daemons (especially the binary utilities and extra scripts for Windows). For Electron/NW.js apps, sudo-prompt has been quite helpful.

License

MIT

porthog's People

Contributors

coreybutler avatar dependabot[bot] avatar greenkeeper[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

porthog's Issues

Error on Windows 7

Hi,
Thank you for all the hard work and all the excellent projects you have shared with the community.
I installed porthog (version 0.4) on a Windows 7 SP1 OS but for some reason when checking for certain ports; it's returning the following error:

porthog 1281

child_process.js:508
    throw err;
    ^

Error: Command failed: netstat -aon | findstr :1281 | findstr LISTENING

    at checkExecSyncError (child_process.js:465:13)
    at execSync (child_process.js:505:13)
    at module.exports.stdout.forEach.Object.keys.forEach (C:\Users\mattjs\AppData\Roaming\npm\node_modules\porthog\index.js:15:16)
    at C:\Users\mattjs\AppData\Roaming\npm\node_modules\porthog\cli.js:15:15
    at Array.forEach (native)
    at Object.<anonymous> (C:\Users\mattjs\AppData\Roaming\npm\node_modules\porthog\cli.js:14:6)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12) 

However when I run the following command, it seems to produce the desired output
porthog 80

PORT      PID       PROCESS
--------------------------------------------------
80        -         -

Any help would be much appreciated, thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.