调用 GetExtendedTcpTable () 时的空响应
Empty response on call GetExtendedTcpTable ()
我是围棋新手,需要在Windows抓网。我尝试使用指向字节数组的指针作为参数来调用 GetExtendedTcpTable()
,但调用后什么也得不到。
var (
iphelp = syscall.NewLazyDLL("iphlpapi.dll")
tcptable = iphelp.NewProc("GetExtendedTcpTable")
)
var (
buffer [20000]byte
table [20000]byte
length int
)
res1, res2, err := tcptable.Call(
uintptr(unsafe.Pointer(&buffer)),
uintptr(unsafe.Pointer(&length)),
1,
syscall.AF_INET,
uintptr(unsafe.Pointer(&table)),
0,
)
我希望 'buffer' 和 'table' 中有一些数据,但只有 0 个。
我做错了什么?
您的代码有两个错误。首先,您传入 legnth=0,这会导致 GetExtendedTcpTable() 变为 return ERROR_INSUFFICIENT_BUFFER
122 (0x7A)。然后,第五个参数不是指向table本身的指针,而是一个输入参数,它将table的class(类型)声明为return(写入参数1. 这是克服这些障碍的更正版本:
import (
"fmt"
"syscall"
"unsafe"
)
const (
TCP_TABLE_BASIC_LISTENER = 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
)
func main() {
var table [2000]byte
var length int = len(table)
iphelp := syscall.NewLazyDLL("iphlpapi.dll")
tcptable := iphelp.NewProc("GetExtendedTcpTable")
length = len(table)
res1, res2, err := tcptable.Call(
uintptr(unsafe.Pointer(&table)),
uintptr(unsafe.Pointer(&length)),
1,
syscall.AF_INET,
TCP_TABLE_BASIC_LISTENER,
0,
)
fmt.Println(res1, res2, length, err)
fmt.Println(table)
}
我通过检查 GetExtendedTcpTable() 的 return 代码发现了这一点。 Microsoft 系统错误代码列于:https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
我是围棋新手,需要在Windows抓网。我尝试使用指向字节数组的指针作为参数来调用 GetExtendedTcpTable()
,但调用后什么也得不到。
var (
iphelp = syscall.NewLazyDLL("iphlpapi.dll")
tcptable = iphelp.NewProc("GetExtendedTcpTable")
)
var (
buffer [20000]byte
table [20000]byte
length int
)
res1, res2, err := tcptable.Call(
uintptr(unsafe.Pointer(&buffer)),
uintptr(unsafe.Pointer(&length)),
1,
syscall.AF_INET,
uintptr(unsafe.Pointer(&table)),
0,
)
我希望 'buffer' 和 'table' 中有一些数据,但只有 0 个。 我做错了什么?
您的代码有两个错误。首先,您传入 legnth=0,这会导致 GetExtendedTcpTable() 变为 return ERROR_INSUFFICIENT_BUFFER 122 (0x7A)。然后,第五个参数不是指向table本身的指针,而是一个输入参数,它将table的class(类型)声明为return(写入参数1. 这是克服这些障碍的更正版本:
import (
"fmt"
"syscall"
"unsafe"
)
const (
TCP_TABLE_BASIC_LISTENER = 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
)
func main() {
var table [2000]byte
var length int = len(table)
iphelp := syscall.NewLazyDLL("iphlpapi.dll")
tcptable := iphelp.NewProc("GetExtendedTcpTable")
length = len(table)
res1, res2, err := tcptable.Call(
uintptr(unsafe.Pointer(&table)),
uintptr(unsafe.Pointer(&length)),
1,
syscall.AF_INET,
TCP_TABLE_BASIC_LISTENER,
0,
)
fmt.Println(res1, res2, length, err)
fmt.Println(table)
}
我通过检查 GetExtendedTcpTable() 的 return 代码发现了这一点。 Microsoft 系统错误代码列于:https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx