Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
Problem :
You need to find out which Linux/Unix or MacOSX applications are listening to port 80( or any other port numbers ). How to do that?
Solution :
Use the lsof
command. lsof
stands for list open files - will lists on console(standard output) the file information opened by processes(programs). An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.)
For example :
>sudo lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1435 root 6u IPv4 10321 0t0 TCP *:http (LISTEN)
nginx 3698 nobody 6u IPv4 10321 0t0 TCP *:http (LISTEN)
From the file descriptor(FD), we can see that the processes use IP version 4. You can filter out lsof
command out further, but specifying which sort of information you want to see.
If you want to list out IPv4 only, then use sudo lsof -i4 :80
For IPv6, use sudo lsof -i6 :80
See also : Unix/Linux : Get reboot history or check when was the last reboot date
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.3k Golang: Prevent over writing file with md5 hash
+8.2k Golang : How to get garbage collection data?
+7.6k Android Studio : Indicate progression with ProgressBar example
+15.2k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+35.1k Golang : Convert date or time stamp from string to time.Time type
+28.8k Golang : Remove characters from string example
+9.4k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+13.9k Golang : Find location by IP address and display with Google Map
+7.6k Golang : Convert(cast) []byte to io.Reader type
+7.3k Android Studio : Import third-party library or package into Gradle Scripts
+11.4k Swift : Convert (cast) Int or int32 value to CGFloat
+12.5k Golang : Human readable time elapsed format such as 5 days ago