- 浏览: 752563 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
package examples.ntp; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; import java.text.NumberFormat; import org.apache.commons.net.ntp.NTPUDPClient; import org.apache.commons.net.ntp.NtpUtils; import org.apache.commons.net.ntp.NtpV3Packet; import org.apache.commons.net.ntp.TimeInfo; import org.apache.commons.net.ntp.TimeStamp; /*** * This is an example program demonstrating how to use the NTPUDPClient Network * time Protocol (NTP) service port on a specified server, retrieves the time, * and prints it to standard output along with the fields from the NTP message * header (e.g. stratum level, reference id, poll interval, root delay, mode, * ...) See <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc868.txt"> the spec * </A> for details. * <p> * Usage: NTPClient <hostname-or-address-list> <br> * Example: NTPClient clock.psu.edu * * @author Jason Mathews, MITRE Corp ***/ public final class NTPClient { private static final NumberFormat numberFormat = new java.text.DecimalFormat( "0.00"); /** * Process <code>TimeInfo</code> object and print its details. * * @param info * <code>TimeInfo</code> object. */ public static void processResponse(TimeInfo info) { NtpV3Packet message = info.getMessage(); int stratum = message.getStratum(); String refType; if (stratum <= 0) refType = "(Unspecified or Unavailable)"; else if (stratum == 1) refType = "(Primary Reference; e.g., GPS)"; // GPS, radio clock, // etc. else refType = "(Secondary Reference; e.g. via NTP or SNTP)"; // stratum should be 0..15... System.out.println(" Stratum: " + stratum + " " + refType); int version = message.getVersion(); int li = message.getLeapIndicator(); System.out.println(" leap=" + li + ", version=" + version + ", precision=" + message.getPrecision()); System.out.println(" mode: " + message.getModeName() + " (" + message.getMode() + ")"); int poll = message.getPoll(); // poll value typically btwn MINPOLL (4) and MAXPOLL (14) System.out.println(" poll: " + (poll <= 0 ? 1 : (int) Math.pow(2, poll)) + " seconds" + " (2 ** " + poll + ")"); double disp = message.getRootDispersionInMillisDouble(); System.out.println(" rootdelay=" + numberFormat.format(message.getRootDelayInMillisDouble()) + ", rootdispersion(ms): " + numberFormat.format(disp)); int refId = message.getReferenceId(); String refAddr = NtpUtils.getHostAddress(refId); String refName = null; if (refId != 0) { if (refAddr.equals("127.127.1.0")) { refName = "LOCAL"; // This is the ref address for the Local // Clock } else if (stratum >= 2) { // If reference id has 127.127 prefix then it uses its own // reference clock // defined in the form 127.127.clock-type.unit-num (e.g. // 127.127.8.0 mode 5 // for GENERIC DCF77 AM; see refclock.htm from the NTP software // distribution. if (!refAddr.startsWith("127.127")) { try { InetAddress addr = InetAddress.getByName(refAddr); String name = addr.getHostName(); if (name != null && !name.equals(refAddr)) refName = name; } catch (UnknownHostException e) { // some stratum-2 servers sync to ref clock device but // fudge stratum level higher... (e.g. 2) // ref not valid host maybe it's a reference clock name? // otherwise just show the ref IP address. refName = NtpUtils.getReferenceClock(message); } } } else if (version >= 3 && (stratum == 0 || stratum == 1)) { refName = NtpUtils.getReferenceClock(message); // refname usually have at least 3 characters (e.g. GPS, WWV, // LCL, etc.) } // otherwise give up on naming the beast... } if (refName != null && refName.length() > 1) refAddr += " (" + refName + ")"; System.out.println(" Reference Identifier:\t" + refAddr); TimeStamp refNtpTime = message.getReferenceTimeStamp(); System.out.println(" Reference Timestamp:\t" + refNtpTime + " " + refNtpTime.toDateString()); // Originate Time is time request sent by client (t1) TimeStamp origNtpTime = message.getOriginateTimeStamp(); System.out.println(" Originate Timestamp:\t" + origNtpTime + " " + origNtpTime.toDateString()); long destTime = info.getReturnTime(); // Receive Time is time request received by server (t2) TimeStamp rcvNtpTime = message.getReceiveTimeStamp(); System.out.println(" Receive Timestamp:\t" + rcvNtpTime + " " + rcvNtpTime.toDateString()); // Transmit time is time reply sent by server (t3) TimeStamp xmitNtpTime = message.getTransmitTimeStamp(); System.out.println(" Transmit Timestamp:\t" + xmitNtpTime + " " + xmitNtpTime.toDateString()); // Destination time is time reply received by client (t4) TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime); System.out.println(" Destination Timestamp:\t" + destNtpTime + " " + destNtpTime.toDateString()); info.computeDetails(); // compute offset/delay if not already done Long offsetValue = info.getOffset(); Long delayValue = info.getDelay(); String delay = (delayValue == null) ? "N/A" : delayValue.toString(); String offset = (offsetValue == null) ? "N/A" : offsetValue.toString(); System.out.println(" Roundtrip delay(ms)=" + delay + ", clock offset(ms)=" + offset); // offset in ms } public static final void main(String[] args) { if (args == null || args.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1); } NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (int i = 0; i < args.length; i++) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(args[i]); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info); } catch (IOException ioe) { ioe.printStackTrace(); } } } catch (SocketException e) { e.printStackTrace(); } client.close(); } }
参数可以在下面选择一个,我测试时候用的是ntp.nasa.gov,
测试结果:
> ntp.nasa.gov/198.123.30.132
Stratum: 1 (Primary Reference; e.g., GPS)
leap=0, version=3, precision=-16
mode: Server (4)
poll: 8 seconds (2 ** 3)
rootdelay=0.00, rootdispersion(ms): 0.85
Reference Identifier: 71.80.83.0 (GPS)
Reference Timestamp: d0e3a8ae.7dee6367 Fri, Jan 21 2011 14:39:42.492
Originate Timestamp: d0e3a851.9ced9168 Fri, Jan 21 2011 14:38:09.613
Receive Timestamp: d0e3a8c6.485327f3 Fri, Jan 21 2011 14:40:06.283
Transmit Timestamp: d0e3a8c6.4856fb74 Fri, Jan 21 2011 14:40:06.283
Destination Timestamp: d0e3a852.16041893 Fri, Jan 21 2011 14:38:10.086
Roundtrip delay(ms)=473, clock offset(ms)=116433
附注1:中国大概能用的NTP时间服务器
server 133.100.11.8 prefer
server 210.72.145.44
server 203.117.180.36 //程序中所用的
server 131.107.1.10
server time.asia.apple.com
server 64.236.96.53
server 130.149.17.21
server 66.92.68.246
server www.freebsd.org
server 18.145.0.30
server clock.via.net
server 137.92.140.80
server 133.100.9.2
server 128.118.46.3
server ntp.nasa.gov
server 129.7.1.66
server ntp-sop.inria.frserver 210.72.145.44(国家授时中心服务器IP地址)
ntpdate 131.107.1.10
ntpdate -s time.asia.apple.com
附注2:NTP概念简介
Network Time
Protocol(NTP)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准
度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。
部分参考自:
http://lshh83.iteye.com/blog/546405
发表评论
-
关于方法访问控制符protected
2012-11-29 10:38 1278http://bbs.csdn.net/topics/3902 ... -
一个基本问题关于引用的
2012-05-15 10:20 1140问: int a = 1; Integer b = new ... -
我對面向對象和過程的理解。
2012-05-02 08:30 1079我的一些理解。 面向过程,是对客观现象的描述,感觉是有一个上 ... -
stack and heap
2012-01-13 23:17 1060我觉得是根据应用方式 和本身特性 才将内存分区的,目的是提 ... -
program experience conclusion
2011-07-11 15:35 10821. check parameters for validit ... -
PreparedStatement's possible designated parameter
2011-04-29 13:45 1004though it's nearly impossible t ... -
clean Log4j
2011-04-12 11:19 1081import org.apache.log4j.BasicCo ... -
about abstract class
2011-04-02 10:34 886yes, we do know abstract class ... -
cvs operations on linux
2011-03-25 09:40 1030http://www.linuxhowtos.org/Syst ... -
regex to exchange two parts
2011-03-24 17:09 1113public class Test { public ... -
About the database locking
2011-03-09 11:02 980http://en.wikipedia.org/wiki/Lo ... -
how to send soap message in java
2011-03-08 10:29 1908import java.io.BufferedReader; ... -
About ShutDownDemo
2011-03-07 15:02 1007public class ShutdownDemo { p ... -
How do you know if an explicit object casting is needed
2011-02-24 16:33 1199通俗来讲,不可能将一只是猫的动物强转为狗 再说Graphic ... -
有关MimeUtility
2011-02-24 13:11 3383import java.io.UnsupportedEncod ... -
C#连接sql server 2008的一件2事
2011-02-24 09:01 2167once upon a time, i came upon o ... -
Shadowing, Overriding, Hiding and Obscuring
2011-02-22 15:15 1180当子类属性与父类属性重叠时 这种叫法上是shadowi ... -
JAXP usage
2011-02-16 16:07 1111import java.io.ByteArrayInputSt ... -
运行一个类,如果classpath中路径带空格就加双引号
2011-02-11 11:25 2819注意是这样加: java -cp .;"d:\my ... -
关于ClassPath中的current directory
2011-01-28 16:40 1165Given: 1. package com.company. ...
相关推荐
测试NTP校时效率,每秒校时次数,也可以完成ntp校时
ntp测试工具,用于上位机与嵌入式之间的测试,供开发人员参考
NTP协议的测试工具 由于google被屏蔽 垃圾百度出来的 都是捆绑恶意软件的 所以可以使用这个软件
超好用的ntp服务器检测工具
"ESXi时间同步测试,与Windows搭建的NTP服务器无法同步的原因" 本文主要讨论了ESXi时间同步测试中遇到的问题,即ESXi无法与Windows搭建的NTP服务器同步,而可以与Linux搭建的NTP服务器同步。为查找问题根源,搭建了...
ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序ntp测试程序...
NTP 闰秒测试结果说明 一、NTP 闰秒测试结果说明 NTP 闰秒测试结果说明是关于 2015 年 6 月 30 日 NTP 闰秒测试结果的说明,里面给出了相关的测试结果。 二、NTP 闰秒测试环境 测试环境包括系统、台数、内核版本...
Linux 下 NTP 服务配置与测试 NTP(Network Time Protocol)是一种网络时间协议,用于同步计算机系统的时间。 Linux 操作系统下配置 NTP 服务可以确保系统时间的准确性和同步性。本文将详细介绍 Linux 下 NTP 服务...
【阿里云-NTP服务器部署与测试【超详细】】 阿里云NTP服务器的部署涉及到Linux系统的硬件时钟和系统时钟管理,以及NTP服务的配置与测试。本指南将详细讲解这一过程。 一、Linux的硬件时钟和系统时钟 硬件时钟是...
使用Visual C++作为开发环境,你可以利用其强大的调试工具和丰富的库支持,更方便地开发和测试NTP客户端。同时,为了提高同步效率和可靠性,还可以考虑使用多线程或多播技术,同时连接多个NTP服务器进行时间同步。 ...
好用的Ntp校对时间工具,可ini配置,可设置自动启动,校时间隔 详见博客https://blog.csdn.net/lightspear/article/details/81905285
标题提及的文档主要讲述了在不同平台上设置和测试NTP服务器的过程,以及测试结果。以下是详细的知识点解释: 1. **NTP服务器的功能**: - NTP服务器的主要任务是确保网络内的设备时间一致,减少时间偏差,提高系统...
二、安装依赖包 yum -y install gcc libcap libcap-devel glibc-devel 三、升级Ntp 1、tar zxf /tmp/ntp-4.2.8p10.tar.gz -C /tmp ...四、检查与测试 1、使用ntpd --version命令查看版本已是最新版
四、测试 NTP 服务器 在命令提示符中输入:w32tm /query /source,回车等待 NTP 服务器返回时间信息。如果显示当前时间,则表示 NTP 服务器搭建成功。 五、局域网内同步时间 使用 NTP 服务器可以实现局域网内的...
NTP 微调和跳跃模式说明 NTP 微调和跳跃模式是 Network Time Protocol(网络时间协议)的两个调整方式,用于解决时间同步问题。微调方式是一种平滑、缓慢的渐进式调整,而跳跃式调整则是一种步进式调整。 微调方式...
NTP客户端配置-linux NTP(Network Time Protocol,网络时间协议)是一种用于同步计算机时钟的协议,常用于确保计算机系统的时钟保持同步,以便于正确记录事件和日志。作为运维人员,配置NTP客户端对系统的稳定运行...
9. **测试与调试**:编写测试用例来验证NTP模块的功能和性能,确保在不同网络条件和服务器环境下都能正常工作。 10. **文档编写**:提供详细的API文档和使用示例,帮助其他开发者理解和使用你的NTP模块。 在“ntp...
4. **测试和验证**: - 在域内客户端上,使用`w32tm /resync /rediscover`命令强制进行时间同步,通过`w32tm /query /status`命令检查NTP服务的状态和时间源。 需要注意的是,如果希望域控制器从外部NTP服务器获取...
NTP时间同步功能测试学习的知识点 在现代工业自动化领域,确保控制系统时间的一致性至关重要。NTP(网络时间协议)提供了一种有效的机制,使得计算机设备和网络系统能够通过网络同步其时钟。欧姆龙NJ/NX系列PLC控制...
为了测试NTP客户端,你可以配置一台Windows 7系统作为时间服务器,或者使用公开的NTP服务器地址。确保服务器配置正确,运行并监听NTP请求。测试客户端时,检查时间同步的准确性,看是否能成功获取并显示服务器的时间...