我正在寻找像这样的东西:
tcpdump -p PID # But tcpdump does not know the PID
要么
lsof -i --continuous # But lsof just runs and exits, no «live logging»
logging应用程序打开的连接。
在我的情况下,我想找出提交时,git连接到哪个端口。 这发生在几分之一秒,所以我不能使用lsof。 如果stream量很大,则通过PID或进程名称筛选将非常有用。
您可以对stream程进行调整。
$ strace -e trace=connect git ... connect(4, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("<your local DNS resolver>")}, 16) = 0 connect(4, {sa_family=AF_INET, sin_port=htons(<PORT>), sin_addr=inet_addr("<GIT SERVER>")}, 16) = 0
在我的情况下,我想找出提交时,git连接到哪个端口。
为什么不:
$ git config --get remote.origin.url
默认端口是:
git:// – 9418 git+ssh:// – 22 http:// – 80 否则,在提交时,git会让你知道它连接的是哪个端口:
$ git config --get remote.origin.url git+ssh://[email protected]:1234/project/repo.git