几何尺寸与公差论坛

 找回密码
 注册
查看: 1595|回复: 0

獲取網絡時間(網絡獲取)

[复制链接]
发表于 2010-4-12 11:39:27 | 显示全部楼层 |阅读模式

  • Dim SvrName(14),xPost,HttpAdd,NowTime,StartTime
  • StartTime=Now
  • //驗證服務器
  • SvrName(1) = "time-nw.nist.gov"
  • //Microsoft, Redmond, Washington 131.107.1.10
  • SvrName(2) = "time-a.nist.gov"
  • //NIST, Gaithersburg, Maryland  129.6.15.28
  • SvrName(3) = "time-b.nist.gov"
  • //NIST, Gaithersburg, Maryland  129.6.15.29
  • SvrName(4) = "time-a.timefreq.bldrdoc.gov"
  • //NIST, Boulder, Colorado  132.163.4.101
  • SvrName(5) = "time-b.timefreq.bldrdoc.gov"
  • //NIST, Boulder, Colorado  132.163.4.102
  • SvrName(6) = "time-c.timefreq.bldrdoc.gov"
  • //NIST, Boulder, Colorado  132.163.4.103
  • SvrName(7) = "utcnist.colorado.edu"
  • //University of Colorado, Boulder  128.138.140.44
  • SvrName(8) = "time.nist.gov"
  • //NCAR, Boulder, Colorado  192.43.244.18
  • SvrName(9) = "nist1.datum.com"
  • //Datum, San Jose, California  66.243.43.21
  • SvrName(10) = "nist1.dc.glassey.com"
  • //Abovenet, Virginia  216.200.93.8
  • SvrName(11) = "nist1.ny.glassey.com"
  • //Abovenet, New York City  208.184.49.9
  • SvrName(12) = "nist1.sj.glassey.com"
  • //Abovenet, San Jose, California  207.126.103.204
  • SvrName(13) = "nist1.aol-ca.truetime.com"
  • //TrueTime, AOL facility, Sunnyvale, CA  207.200.81.113
  • SvrName(14) = "nist1.aol-va.truetime.com"
  • //TrueTime, AOL facility, Virginia  205.188.185.33
  • //調用XMLHTTP
  • Set xPost=createObject("Microsoft.XMLHTTP")
  • Set Obj=createObject("Wscript.shell")
  • While NowTime=""
  •     i=1
  •     For 14
  •         HttpAdd="Http://"&SvrName(i)&":13":NowTime=""
  •         xPost.Open "ut",HttpAdd,False
  •         //以同步方式打開此連接
  •         xPost.Send()
  •         //送請求到http服務器並接收回應
  •         Delay 10
  •         //適當延時以接收數據
  •         If xPost.readyState=4
  •             //如果獲得數據完畢OR連接超時
  •             NowTime=mid(xPost.responsetext,8,17)
  •             //以字符串返回響應信息
  •             If NowTime<>""
  •                 NowTime=CDate(NowTime) + 8 / 24
  •                 Obj.popup "當前標准時間:"&NowTime,0,"網絡時間"
  •                 Goto EndConnect
  •            Else
  •               xPost.abort()
  •               NowTime=""
  •           EndIf
  •     EndIf
  •     i=i+1
  • EndFor
  • //如果一定時間沒有連接上,說明出暸問題
  • If DateDiff("s",StartTime,Now)>=30 And NowTime=""
  •     Obj.popup "請確定妳已經連接上暸互聯網!",0,"網絡時間"
  •     Goto EndConnect
  • EndIf
  • EndWhile
  • Rem EndConnect
  • xPost.abort()
  • Set xPost=Nothing
  • NowTime=""
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-5-5 18:28 , Processed in 0.034844 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表