英文:
Listen from all the ports
问题
我正在编写一个程序,它可以监听从一个接口发送出去的所有数据包。我已经阅读了net
的文档,但是我在那里找到的所有可能的方法都需要以host:port
的形式提供addr
参数。我想要读取从一个网络接口发送出去的所有数据包。你有什么建议吗?
英文:
I'm writing a program which listen all the packets which come out from an interface. I've read the net
godoc but all the possible methods I've found there require the addr
in the form host:port
. I would read all the packets which go out from one network interface. Do you have any suggestions?
答案1
得分: 2
你无法一次绑定到所有端口而不单独监听它们,我相信这不是你在问题的最后一句话中的意思。
我认为你真正需要的是一个数据包捕获库,比如gopacket/pcap。
英文:
You can't bind to all ports at once without listening on them separately, and I'm pretty sure that's not what you mean in the last sentence of your question.
I think what you're really after is a packet capture library, like gopacket/pcap.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论