2015-11-03 75 views
2

送他们我有一个巴投影机,我想远程控制自己。如何解释Wireshark的消息,并用C#

巴有自己tool要做到这一点,但完全用Java编写的。

当我赶数据被发送到SWITH到HDMI信号源使用Wireshark我得到如下:

0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E. 
0010 00 31 51 72 40 00 80 06 00 00 0a 00 00 0d 0a 00 [email protected] 
0020 00 3e ef e1 04 01 c2 67 14 b8 9e da c6 b2 50 18 .>.....g......P. 
0030 01 00 14 6e 00 00 3a 49 48 44 4d 20 31 20 0d  ...n..:IHDM 1 . 


0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E. 
0010 00 28 51 73 40 00 80 06 00 00 0a 00 00 0d 0a 00 .([email protected] 
0020 00 3e ef e1 04 01 c2 67 14 c1 9e da c6 c4 50 10 .>.....g......P. 
0030 01 00 14 65 00 00        ...e.. 

并切换回DVI,我得到:

0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E. 
0010 00 31 53 1e 40 00 80 06 00 00 0a 00 00 0d 0a 00 [email protected] 
0020 00 3e ef e1 04 01 c2 67 14 c1 9e da c6 c4 50 18 .>.....g......P. 
0030 01 00 14 6e 00 00 3a 49 44 56 49 20 31 20 0d  ...n..:IDVI 1 . 


0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E. 
0010 00 28 53 20 40 00 80 06 00 00 0a 00 00 0d 0a 00 .(S @........... 
0020 00 3e ef e1 04 01 c2 67 14 ca 9e da c6 d6 50 10 .>.....g......P. 
0030 00 ff 14 65 00 00        ...e.. 

我试着一些事情在C#中,但很少成功:

IPAddress beamerIP = new IPAddress(IpToBin("!!Beamer IP!!")); 
IPEndPoint ip = new IPEndPoint(beamerIP, 1025); 
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 

socket.Connect(ip); 
Console.WriteLine("Socket connected to " + socket.RemoteEndPoint.ToString()); 

byte[] msg = Encoding.ASCII.GetBytes(":IDVI 1 ."); 
byte[] dvi = new byte[] { 0x3a, 0x49, 0x44, 0x56, 0x49, 0x20, 0x31, 0x20, 0x0d }; 
byte[] hdmi = new byte[] { 0x3a, 0x49, 0x48, 0x44, 0x4d, 0x20, 0x31, 0x20, 0x0d }; 

int bytesSent = socket.Send(dvi); 
Console.WriteLine("Sent {0} bytes.", bytesSent); 

socket.Shutdown(SocketShutdown.Both); 
socket.Close(); 

我也试着用PCAP.NET发送像在th是thread,但收效甚微。

我做得不对或有另一种方法呢?

回答

0

原来我几乎在那里。这是为我工作的代码:

// Data buffer for incoming data. 
byte[] bytes = new byte[1024]; 
// Establish the remote endpoint for the socket. 
IPAddress beamerIP = new IPAddress(IpToBin("!!Beamer IP!!")); 
IPEndPoint ip = new IPEndPoint(beamerIP, 1025); 
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); 
socket.Connect(ip); 
// Send the data through the socket. 
int bytesSent = socket.Send(message); //message => DVI = Encoding.ASCII.GetBytes(":IDVI 1 \r") || HDMI = Encoding.ASCII.GetBytes(":IHDM 1 \r") 
// Receive the response from the remote device. 
int bytesRec = socket.Receive(bytes); 
// Release the socket. 
socket.Shutdown(SocketShutdown.Both); 
socket.Close();