同一网络中的服务器中的时间 [英] time in Servers at the same network
本文介绍了同一网络中的服务器中的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问如何获取网络中每个服务器的时间
示例:我不会在计算机上运行应用程序以了解网络中每台服务器的确切时间.
在此先感谢
can i please ask how to get the time in each server in my network
example : I wont to run application on my computer to know what the exact time in each server in my network
Thanks in advance
推荐答案
从C#.Net中的另一台机器获取时间:
http://joymonscode.blogspot.co.il/2012/06/getting-time-from-another-machine-in.html [
Getting time from another machine in C#.Net:
http://joymonscode.blogspot.co.il/2012/06/getting-time-from-another-machine-in.html[^]
您可以使用以下代码:
You may use this code:
System.Net.Sockets.TcpClient t = new System.Net.Sockets.TcpClient("panic", 13);
System.IO.StreamReader rd = new System.IO.StreamReader(t.GetStream());
MessageBox.Show(rd.ReadToEnd());
但它要求您可以访问服务器上的端口13.
或者您可以使用以下代码尝试命令行命令"net time \\ servername":
but it requires that port 13 on the server is accessible for you.
Or you may try the command line command "net time \\servername" using this code:
System.Diagnostics.ProcessStartInfo psiOpt = new System.Diagnostics.ProcessStartInfo(@"cmd.exe", @"/C net time \\servername");
psiOpt.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psiOpt.RedirectStandardOutput = true;
psiOpt.UseShellExecute = false;
psiOpt.CreateNoWindow = true;
System.Diagnostics.Process procCommand = System.Diagnostics.Process.Start(psiOpt);
StreamReader srIncoming = procCommand.StandardOutput;
MessageBox.Show(srIncoming.ReadToEnd());
procCommand.WaitForExit();
然后,您只需要解析DateTime的命令响应.
You then only need to parse the command response for the DateTime.
这篇关于同一网络中的服务器中的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文