我正在寻找可以查看UDP连接的任何类型的端口侦听器。原因是我正在尝试编写一个程序来查看人们在游戏中聊天的内容并做出相应的响应。 [并希望创建一个用于举办锦标赛的服务器自动贩卖机]
我已经尝试了一个VB.NET解决方案,但它会关闭连接,尽管数小时试图让它并排进行连接。
Imports System.Net Imports System.Net.Sockets Public Class Form1 Public Sub Form1_Load() Handles Me.Load 'Do 'Dim iReceivingPort As Integer = 58690 'Creates a UdpClient for reading incoming data. 'Dim inEndPoint = New IPEndPoint(IPAddress.Parse("192.168.1.100"), iReceivingPort) 'Dim endPoint = New IPEndPoint(IPAddress.Parse("192.168.1.100"), iReceivingPort) 'System.Net.IPAddress.Parse("0.0.0.0"), iReceivingPort 'Dim ReceivingClient = New System.Net.Sockets.UdpClient() 'ReceivingClient.ExclusiveAddressUse = False 'ReceivingClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True) 'ReceivingClient.Client.Bind(inEndPoint) Dim ip = IPAddress.Parse("192.168.1.100") Dim port = 65267 Dim socket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True) socket.Bind(New IPEndPoint(ip, port)) 'Creates an IPEndPoint to record the IP address and port number of the sender. ' The IPEndPoint will allow you to read datagrams sent from any source. 'Dim RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), iReceivingPort) Try ' Blocks until a message returns on this socket from a remote host. Dim buffer Dim receiveBytes As [Byte]() = socket.Receive(buffer) Dim returnData As String = System.Text.Encoding.ASCII.GetString(receiveBytes) Console.WriteLine(("This is the message you received " + returnData.ToString())) 'Console.WriteLine(("This message was sent from " + inEndPoint.Address.ToString() + " on their port number " + inEndPoint.Port.ToString())) Catch e As Exception Console.WriteLine(e.ToString()) End Try ' System.Threading.Thread.Sleep(1000) ' ReceivingClient.Close() 'Loop End Sub 'MyUdpClientCommunicator End Class
找到解决方案,如果有人想要的话:[PYTHON]
import socket, struct
# the public network interface
HOST = socket.gethostbyname(socket.gethostname())
# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind(("192.168.1.100", 63578))
while 1:
# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receive all packages
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
# receive a package
packet, address = s.recvfrom(65565)
print(packet)
# disabled promiscuous mode
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
代码不完整,但这就是我需要的内容。
答案 0 :(得分:1)
您可能想要查看nMap http://nmap.org/book/nping-man-udp-mode.html
答案 1 :(得分:1)
尝试学习ruby https://www.ruby-lang.org/en/然后使用套接字gem来处理套接字。这很容易学习。