winnetstat

package module
v0.0.0-...-efa1aff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 5 Imported by: 4

README

win-netstat

GoDoc

windows netstat implementation in Golang.

Getting Started

package main

import (
	"fmt"
	"log"

	"github.com/pytimer/win-netstat"
)

func tcp4() {
	conns, err := winnetstat.Connections("tcp4")
	if err != nil {
		log.Fatal(err)
	}
	for _, conn := range conns {
		fmt.Printf("%s:%d\t%d\t%s\n", conn.LocalAddr, conn.LocalPort, conn.OwningPid, conn.State)

	}
}

func tcp4WithPid(pid int) {
	conns, err := winnetstat.ConnectionsWithPid("tcp4", pid)
	if err != nil {
		log.Fatal(err)
	}
	for _, conn := range conns {
		fmt.Printf("%s:%d\t%d\t%s\n", conn.LocalAddr, conn.LocalPort, conn.OwningPid, conn.State)
	}
}

func main() {
	tcp4()
	tcp4WithPid(3848)
}

Examples

examples

Dependencies

kbinani/win

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const ANY_SIZE = 1

Variables

View Source
var TCPStatuses = map[MIB_TCP_STATE]string{
	1:  "CLOSED",
	2:  "LISTEN",
	3:  "SYN_SENT",
	4:  "SYN_RECEIVED",
	5:  "ESTABLISHED",
	6:  "FIN_WAIT_1",
	7:  "FIN_WAIT_2",
	8:  "CLOSE_WAIT",
	9:  "CLOSING",
	10: "LAST_ACK",
	11: "TIME_WAIT",
	12: "DELETE",
}

TCPStatuses https://msdn.microsoft.com/en-us/library/windows/desktop/bb485761(v=vs.85).aspx

Functions

func GetExtendedTcpTable

func GetExtendedTcpTable(pTcpTable uintptr, pdwSize *uint32, bOrder bool, ulAf uint32, tableClass TCP_TABLE_CLASS, reserved uint32) (errcode error)

func GetExtendedUdpTable

func GetExtendedUdpTable(pUdpTable uintptr, pdwSize *uint32, bOrder bool, ulAf uint32, tableClass UDP_TABLE_CLASS, reserved uint32) (errcode error)

func GetTcp6Table2

func GetTcp6Table2(tcpTable PMIB_TCP6TABLE2, bufSize *uint32, order bool) (errcode error)

func GetTcpTable2

func GetTcpTable2(tcpTable PMIB_TCPTABLE2, bufSize *uint32, order bool) (errcode error)

Types

type IN6_ADDR

type IN6_ADDR struct {
	U IN6_ADDR_U
}

type IN6_ADDR_U

type IN6_ADDR_U struct {
	Uchar  [16]byte
	Ushort [8]uint16
}

func (*IN6_ADDR_U) GetByte

func (u *IN6_ADDR_U) GetByte() [16]byte

type MIB_TCP6ROW2

type MIB_TCP6ROW2 struct {
	LocalAddr       IN6_ADDR
	DwLocalScopeId  uint32
	DwLocalPort     uint32
	RemoteAddr      IN6_ADDR
	DwRemoteScopeId uint32
	DwRemotePort    uint32
	State           MIB_TCP_STATE
	DwOwningPid     uint32
	DwOffloadState  TCP_CONNECTION_OFFLOAD_STATE
}

type MIB_TCP6ROW_OWNER_PID

type MIB_TCP6ROW_OWNER_PID struct {
	UcLocalAddr     [16]byte
	DwLocalScopeId  uint32
	DwLocalPort     uint32
	UcRemoteAddr    [16]byte
	DwRemoteScopeId uint32
	DwRemotePort    uint32
	DwState         uint32
	DwOwningPid     uint32
}

type MIB_TCP6TABLE2

type MIB_TCP6TABLE2 struct {
	DwNumEntries uint32
	Table        [ANY_SIZE]MIB_TCP6ROW2
}

type MIB_TCP6TABLE_OWNER_PID

type MIB_TCP6TABLE_OWNER_PID struct {
	DwNumEntries uint32
	Table        [ANY_SIZE]MIB_TCP6ROW_OWNER_PID
}

type MIB_TCPROW2

type MIB_TCPROW2 struct {
	DwState        uint32
	DwLocalAddr    uint32
	DwLocalPort    uint32
	DwRemoteAddr   uint32
	DwRemotePort   uint32
	DwOwningPid    uint32
	DwOffloadState TCP_CONNECTION_OFFLOAD_STATE
}

type MIB_TCPROW_OWNER_PID

type MIB_TCPROW_OWNER_PID struct {
	DwState      uint32
	DwLocalAddr  uint32
	DwLocalPort  uint32
	DwRemoteAddr uint32
	DwRemotePort uint32
	DwOwningPid  uint32
}

type MIB_TCPTABLE2

type MIB_TCPTABLE2 struct {
	DwNumEntries uint32
	Table        [ANY_SIZE]MIB_TCPROW2
}

type MIB_TCPTABLE_OWNER_PID

type MIB_TCPTABLE_OWNER_PID struct {
	DwNumEntries uint32
	Table        [ANY_SIZE]MIB_TCPROW_OWNER_PID
}

type MIB_TCP_STATE

type MIB_TCP_STATE int32

type MIB_UDP6ROW_OWNER_PID

type MIB_UDP6ROW_OWNER_PID struct {
	UcLocalAddr    [16]byte
	DwLocalScopeId uint32
	DwLocalPort    uint32
	DwOwningPid    uint32
}

type MIB_UDP6TABLE_OWNER_PID

type MIB_UDP6TABLE_OWNER_PID struct {
	DwNumEntries uint32
	Table        [ANY_SIZE]MIB_UDP6ROW_OWNER_PID
}

type MIB_UDPROW_OWNER_PID

type MIB_UDPROW_OWNER_PID struct {
	DwLocalAddr uint32
	DwLocalPort uint32
	DwOwningPid uint32
}

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365930(v=vs.85).aspx

type MIB_UDPTABLE_OWNER_PID

type MIB_UDPTABLE_OWNER_PID struct {
	DwNumEntries uint32
	Table        [ANY_SIZE]MIB_UDPROW_OWNER_PID
}

type NetStat

type NetStat struct {
	LocalAddr  string
	LocalPort  uint16
	RemoteAddr string
	RemotePort uint16
	OwningPid  int
	State      string
}

NetStat return a netstat record

func Connections

func Connections(kind string) ([]NetStat, error)

Connections list all netstats include: tcp tcp6 udp udp6

func ConnectionsWithPid

func ConnectionsWithPid(kind string, pid int) ([]NetStat, error)

ConnectionsWithPid list specfic pid netstats include: tcp tcp6 udp udp6

type PMIB_TCP6TABLE2

type PMIB_TCP6TABLE2 *MIB_TCP6TABLE2

type PMIB_TCP6TABLE_OWNER_PID_ALL

type PMIB_TCP6TABLE_OWNER_PID_ALL *MIB_TCP6TABLE_OWNER_PID

type PMIB_TCPTABLE2

type PMIB_TCPTABLE2 *MIB_TCPTABLE2

type PMIB_TCPTABLE_OWNER_PID_ALL

type PMIB_TCPTABLE_OWNER_PID_ALL *MIB_TCPTABLE_OWNER_PID

type PMIB_UDP6TABLE_OWNER_PID

type PMIB_UDP6TABLE_OWNER_PID *MIB_UDP6TABLE_OWNER_PID

type PMIB_UDPTABLE_OWNER_PID

type PMIB_UDPTABLE_OWNER_PID *MIB_UDPTABLE_OWNER_PID

type TCP_CONNECTION_OFFLOAD_STATE

type TCP_CONNECTION_OFFLOAD_STATE int32
const (
	TcpConnectionOffloadStateInHost TCP_CONNECTION_OFFLOAD_STATE = iota
	TcpConnectionOffloadStateOffloading
	TcpConnectionOffloadStateOffloaded
	TcpConnectionOffloadStateUploading
	TcpConnectionOffloadStateMax
)

type TCP_TABLE_CLASS

type TCP_TABLE_CLASS int32
const (
	TCP_TABLE_BASIC_LISTENER TCP_TABLE_CLASS = iota
	TCP_TABLE_BASIC_CONNECTIONS
	TCP_TABLE_BASIC_ALL
	TCP_TABLE_OWNER_PID_LISTENER
	TCP_TABLE_OWNER_PID_CONNECTIONS
	TCP_TABLE_OWNER_PID_ALL
	TCP_TABLE_OWNER_MODULE_LISTENER
	TCP_TABLE_OWNER_MODULE_CONNECTIONS
	TCP_TABLE_OWNER_MODULE_ALL
)

type UDP_TABLE_CLASS

type UDP_TABLE_CLASS int32
const (
	UDP_TABLE_BASIC UDP_TABLE_CLASS = iota
	UDP_TABLE_OWNER_PID
	UDP_TABLE_OWNER_MODULE
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL