Mac 下netstat和linux下不一样

Linux's netstat command options and OS X(/BSD)'s have almost nothing to do with each other. Of the options you're invoking, only -n means the same on both, and some of the others (-l and -p) have no equivalent on OS X's netstat. What I habitually use on OS X is netstat -an | grep LISTEN, but that doesn't show UDP or the program involved. I suppose you could use netstat -an | egrep '^udp|LISTEN' to include UDP, but that's rather verbose (and you'll also see quite a bit of nonsense UDP stuff, since there isn't really a concept of UDP listening vs. other states). If you need to know the program, you need to go to the lsof (list open files) command, and that requires root access to check processes you don't own. Try something like sudo lsof -nPi -sTCP:LISTEN

 

 
原文地址:https://www.cnblogs.com/zhaoxinshanwei/p/8696755.html