[go-nuts] "github.com/google/gopacket" package alternative

2018-04-20 Thread Binu Paul
Hi

   any alternative library available for

"github.com/google/gopacket" which generate live traffic



Regards,

Binu

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Tcp connection reset

2018-04-17 Thread Binu Paul
Hi,



package main

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

//var started_at time.Time
//var rest_root_requests int64 = 0


func main() {
   fmt.Println("live test")

   defender_loop()
}



var (
   device   string = "eth0"
   snapshot_len int32  = 1024
   promiscuous  bool   = false
   err  error
   timeout  time.Duration = 5
   handle   *pcap.Handle
   // Will reuse these for each packet
   ethLayer layers.Ethernet
   ipLayer  layers.IPv4
   tcpLayer layers.TCP
)


func defender_loop() {

   //var dstIPstr string = "127.0.0.1"
   //
   //if handle, err := pcap.OpenOffline("test.pcap"); err != nil {
   // //panic()
   // fmt.Print("kjhk")
   //}


   if handle, err := pcap.OpenLive("eth0", 1600, false, 5); err != nil {
  panic(err)
  fmt.Println(err);
   } else {
fmt.Print(handle)
  var filter string = "tcp and port 80"
  err = handle.SetBPFFilter(filter)
  if err != nil {
 log.Fatal(err)
  }
  fmt.Println("Only capturing TCP port 22 packets.")
  packetSource := gopacket.NewPacketSource(handle,
handle.LinkType())
  for packet := range packetSource.Packets() {
 //handlePacket(packet)  // Do something with a packet here.

 parser := gopacket.NewDecodingLayerParser(
layers.LayerTypeEthernet,
,
,
,
 )
 foundLayerTypes := []gopacket.LayerType{}

 err := parser.DecodeLayers(packet.Data(), )
 if err != nil {
//fmt.Println("Trouble decoding layers: ", err)
continue
 }
 //fmt.Printf("Founder Layer>%+v\n", foundLayerTypes)
 for _, layerType := range foundLayerTypes {

//fmt.Println();
//fmt.Printf("ipLayer-->%+v\n", ipLayer)
//fmt.Println();
if(ipLayer.SrcIP.String() =="192.168.1.3") {
 //ipLayer.SrcIP=ipLayer.DstIP;
   //ipLayer.DstIP=ipLayer.SrcIP;
   //if(tcpLayer.SrcPort==61585) {
fmt.Println("Inside  IP");
   if(tcpLayer.RST==false){
  //fmt.Println("Before Update");
  fmt.Printf("%+v\n", tcpLayer)

  //fmt.Println();
  tcpLayer.RST=true;
  tcpLayer.Ack=0;
tcpLayer.ACK=false;
  //fmt.Println("After Update");

   }
   //fmt.Printf("%+v\n", tcpLayer)
}
if layerType == layers.LayerTypeIPv4 {
   //fmt.Println("IPv4: ",
ipLayer.SrcIP, "->", ipLayer.DstIP)
   // fmt.Printf("ipLayer-->%+v\n", ipLayer)

}


payload := gopacket.Payload([]byte("testing"))
buf := gopacket.NewSerializeBuffer()
opts := gopacket.SerializeOptions{
   //FixLengths:   true,
   ComputeChecksums: true,
}

tcpLayer.SetNetworkLayerForChecksum()
err := gopacket.SerializeLayers(buf, opts,
   ,
   ,
   payload)
if err != nil {
   panic(err)
}
packetData := buf.Bytes()
ipConn, err := net.ListenPacket("ip4:tcp",
"0.0.0.0")
if err != nil {
   panic(err)
}

dstIPaddr := net.IPAddr{
   IP: ipLayer.SrcIP,
}

_, err = ipConn.WriteTo(packetData, )
if err != nil {
   panic(err)
}

Re: [go-nuts] Tcp connection reset

2018-04-13 Thread Binu Paul
i need to reset the tcp connection manually , if one request come from
ipLayer.SrcIP
= 10.2.3.1 then i need to sent the reset connection packet

On Fri, Apr 13, 2018 at 6:30 PM, Jesper Louis Andersen <
jesper.louis.ander...@gmail.com> wrote:

> TCP connections are normally Close()'d, which starts the gracefully dance
> of sending FIN packets back and forth. RST is a far more abrupt situation,
> which is normally reserved for a few exceptional cases. I find it rare that
> one needs the RST from the userland outside kernel jurisdiction. Hence my
> curiosity: what are you trying to achieve in the first place?
>
>
> On Fri, Apr 13, 2018 at 2:28 PM Binu Ps  wrote:
>
>> HI
>>
>>  I need  to reset  tcp connection,
>> any library available in golang ?
>>  Concept :  if one connection coming  from ipLayer.SrcIP = 10.2.3.1 ,
>> then i need to reset the connection (tcpLayer.RST=true;) and need to
>> form a packet and  sent request reset the cnnection   is it possible in
>> golang
>>
>> Regards,
>> Binu
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.