首页 > 移动平台 > 详细

golang简单实现netbios远程查询机器名字

时间:2021-04-15 09:13:08      阅读:29      评论:0      收藏:0      [点我收藏+]
package main

import (
	"fmt"
	"net"
)

func main() {
	// 创建连接
	socket, err := net.DialUDP("udp4", nil, &net.UDPAddr{
		IP:   net.IPv4(192, 168, 125, 68),
		Port: 137,
	})
	if err != nil {
		fmt.Println("连接失败!", err)
		return
	}
	defer socket.Close()
	// 发送数据
	senddata := []byte{0x80,0x94,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x43,0x4b,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x00,0x00,0x21,0x00,0x01}
	_, err = socket.Write(senddata)
	if err != nil {
		fmt.Println("发送数据失败!", err)
		return
	}
	// 接收数据
	data := make([]byte, 4096)
	fmt.Println("a")
	read, remoteAddr, err := socket.ReadFromUDP(data)
	if err != nil {
		fmt.Println("读取数据失败!", err)
		return
	}
	fmt.Println(read, remoteAddr)
	flag := 0
	for i := read - 1; i >= 0; i-- {
		if data[i] == 28 {
			flag = i
			break
		}

	}

	fmt.Println(data[:flag])
	fmt.Printf("%s\n",data[57:flag])


}

  

golang简单实现netbios远程查询机器名字

原文:https://www.cnblogs.com/yakoazz/p/14660764.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!