2015-02-06 131 views
0

我正在寻找任何可以查看UDP连接的端口侦听器。原因是我正在编写一个程序,用于查看人们在游戏中聊天的内容并作出相应的回应。 [并希望创造拿着比赛服务器的Automator]任何语言 - 端口监听器? [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) 

的代码是不完整的,但它是什么,我需要个大气压。

回答

1
+0

这是有用的,但我可以用它的宏/沟通? – 2015-02-06 22:10:43

+0

不完全确定。这可能是一个起点。 [http://nmap.org/book/nse-api.html]。我很抱歉,我知道这些并不是最有用的答案(f.ex.步骤1,2,3 ...),但也许他们会让你走向正确的方向。 – 2015-02-06 22:16:07

+0

非常感谢! ;) - NVM链接是死 – 2015-02-06 22:18:39