我的openwrt学习笔记(二十二):网络时间同步
来源:互联网 发布:java 静态代理原理 编辑:程序博客网 时间:2024/05/17 02:48
在实际的LINUX 开发中,网络设备都有工作时间,一般需要进行网络时间同步。
一般采用NTP服务器进行同步。
NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。
它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)进行时间同步,它可以提供高精准度的时间校正,而且可以使用加密确认的方式来防止恶毒的协议攻击。
对嵌入式设备而言,NTP方式关键在于选择哪个NTP服务器,因为有的NTP服务器有时候会出现些问题,如无法访问!
本文介绍一种利用HTTP header信息的方法,需要借助curl,curl是什么后面会进行分析阐述。
需要一定的shell http知识哦!
linux@ubuntu:~/http/testcurl$ curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0| awk -F': ' '/Date: / {print $2}'
Mon, 24 Aug 2015 11:19:25 GMT
linux@ubuntu:~/http/testcurl$ date -s "curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0| awk -F': ' '/Date: / {print $2}'"
date: invalid date `curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0| awk -F\': \' \'/Date: / {print }\''
linux@ubuntu:~/http/testcurl$ date -s "`curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0| awk -F': ' '/Date: / {print $2}'`"
date: cannot set date: Operation not permitted
Mon Aug 24 19:20:00 CST 2015
linux@ubuntu:~/http/testcurl$ sudo date -s "`curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0| awk -F': ' '/Date: / {print $2}'`"
[sudo] password for linux:
Sorry, try again.
[sudo] password for linux:
Mon Aug 24 19:20:09 CST 2015
换个国内的baidu.com吧,再来测试下。
linux@ubuntu:~/http/testcurl$ sudo date -s "`curl -sI www.baidu.com| awk -F': ' '/Date: / {print $2}'`"
[sudo] password for linux:
Wed Aug 26 13:48:49 CST 2015
linux@ubuntu:~/http/testcurl$ curl -sI www.baidu.com
HTTP/1.1 200 OK
Date: Wed, 26 Aug 2015 05:49:09 GMT
Content-Type: text/html; charset=utf-8
Connection: Keep-Alive
Vary: Accept-Encoding
Set-Cookie: BAIDUID=5B78DC1DCE22807CBA79CEBA91B125CB:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BIDUPSID=5B78DC1DCE22807CBA79CEBA91B125CB; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: PSTM=1440568149; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BDSVRTM=0; path=/
Set-Cookie: BD_HOME=0; path=/
Set-Cookie: H_PS_PSSID=16415_1428_14602_12868_16799_16904_17000_17004_12835_15582_12338_13932_16950_16968_16866; path=/; domain=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Cache-Control: private
Cxy_all: baidu+005986c4967689962c9f01e2f019a0d3
Expires: Wed, 26 Aug 2015 05:49:02 GMT
X-Powered-By: HPHP
Server: BWS/1.1
X-UA-Compatible: IE=Edge,chrome=1
BDPAGETYPE: 1
BDQID: 0xfc0fed0200000131
BDUSERID: 0
linux@ubuntu:~/http/testcurl$ curl -sI www.baidu.com| awk -F': ' '/Date: / {print $2}
> ^C
linux@ubuntu:~/http/testcurl$ curl -sI www.baidu.com| awk -F': ' '/Date: / {print $2}'
Wed, 26 Aug 2015 05:49:31 GMT
MT 7688 Openwrt 中完全可以使用这种方式进行网络时间的同步!
- 我的openwrt学习笔记(二十二):网络时间同步
- 我的openwrt学习笔记(二十五):MTK7688 elian一键配置时间测量
- 我的openwrt学习笔记(二):OpenWrt 开发环境搭建
- 我的openwrt学习笔记(三十二):openwrt 的UCI
- 我的openwrt学习笔记(一):OpenWrt简介
- 我的openwrt学习笔记(四):OpenWrt源代码下载
- 我的openwrt学习笔记(二十):WIFI 无线传输速率测试-iperf
- 我的openwrt学习笔记(二十一):广域网IP地址获取_socket http
- 我的openwrt学习笔记(二十三):MTK7688 elian一键配置原理
- 我的openwrt学习笔记(二十四):WIFI无线传输速率相对测试方法_netcat
- 我的openwrt学习笔记(二十六):smartconfig一键配置udp原理
- 我的openwrt学习笔记(二十七)MT7688 NVRAM操作
- 我的openwrt学习笔记(二十八)webserver之lighttpd
- 我的openwrt学习笔记(二十九)webserver之 thttpd
- 我的openwrt学习笔记(二十六):smartconfig一键配置udp原理
- 我的php学习笔记(二十二)php的面向对象开发(九)
- 学习笔记(二十二)
- 我的openwrt学习笔记(十五):Rz sz文件传输
- Android ListView异步加载图片乱序问题,原因分析及解决方案
- C++ sqlite中文插入,模糊读取
- Spring MVC入门案例(2)
- HDU 1698 Just a Hook
- 组合二叉树[二叉查找树+大根堆]
- 我的openwrt学习笔记(二十二):网络时间同步
- Android中解决网络连接异常
- Android性能优化典范(二)
- PHP分页类代码
- C++ 范式工厂
- 刘备的决心
- struts2学习笔记——04
- UDP单播小例子 C#
- Android调用系统相机照相,并显示在下拉列表上