在Internet界面上侦听时是否有丢弃数据包的方法?

假设HTTP服务器在端口8080上运行。我希望“ eth0”上的所有具有目标端口8080的数据包 在它们的TCP标头中,并且满足一些其他条件(例如,URG标志已打开)以在到达服务器之前将其丢弃(换句话说,服务器应该看不到这些数据包)。 像“防火墙”。</ p>

我需要执行Go。 到目前为止,我设法捕获了“ eth0”上的网络流量,并且我知道如何对其进行过滤。 有什么方法可以丢弃由以下程序捕获的数据包:</ p>

  package main 

import(
“ github.com/google/gopacket” \ n“ github.com/google/gopacket/pcap"
” fmt“
” log“
” time“

var(
设备字符串=” en0“
snaplen int32 = 65535 \ n promisc bool = false
err错误
超时时间。Duration= -1 * time.Second
句柄* pcap.Handle

func main(){
句柄,err = pcap.OpenLive( device,snaplen,promisc,timeout)
如果err!= nil {
log.Fatal(err)
}
延迟handle.Close()

packetSource:= gopacket.NewPacketSource(handle,handle。 数据包的LinkType())

:=范围packetSource.Packets(){
fmt.Println(packet)
}
}
</ code> </ pre>
</ div>

展开原文

原文

Let's say an HTTP server is running on port 8080. I want all packets on "eth0" that have destination port 8080 in their TCP header and some other condition is met(for instance URG flag is up) to be dropped before reaching the server (with other words the server should not be able to see these packets). Something like a "firewall".

I need a Go implementation. So far I managed to capture the network traffic on "eth0" and I know how to filter it. Is there any way I can drop the packets that I captured by the following program:

package main

import (
    "github.com/google/gopacket"
    "github.com/google/gopacket/pcap"
    "fmt"
    "log"
    "time"
)

var (
    device string = "en0"
    snaplen int32 = 65535
    promisc bool = false
    err error
    timeout time.Duration = -1 * time.Second
    handle *pcap.Handle
)

func main() {
    handle, err = pcap.OpenLive(device,snaplen,promisc,timeout)
    if err != nil {
        log.Fatal(err)
    }
    defer handle.Close()

    packetSource := gopacket.NewPacketSource(handle,handle.LinkType())

    for packet := range packetSource.Packets() {
        fmt.Println(packet)
    }
}

dongpan1308
dongpan1308 他正在使用pcap库进行低级访问,而不再使用应用程序层
大约一年之前 回复
doujiao3072
doujiao3072 数据包不在应用层处理,因此答案是否定的
大约一年之前 回复

1个回答



您可以尝试通过netmap https://github.com/pragus/gonetmap </ p>
</ div>

展开原文

原文

You can try to do it with go binding of netmap https://github.com/pragus/gonetmap

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐