2015-02-06 127 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