golang编写ping失败,求大神指点

taoshuye · · 2199 次点击
windows 7以上系统要先以管理员身份打开cmd,然后在执行。
#10
更多评论
把conn, err := net.DialIP("ip4:icmp", &laddr, &raddr) 换成 conn, err := net.Dial("ip4:icmp", address) 试试
#1
换掉以后,并注解掉//laddr net.IPAddr = net.IPAddr{IP: net.ParseIP("192.168.31.11")} // raddr net.IPAddr = net.IPAddr{IP: net.ParseIP("192.168.31.1")}两行,仍显示: socket: An attempt was made to access a socket in a way forbidden by its access permissions.
#2