Ask Google for the time
Posted: Thu Dec 11, 2014 10:43 am
A simple script to grab a time stamp from Google.
If you are behind the Great Chinese Firewall, you may have to change Google.com to Baidu.com, but in most places Google will have a close server with an accurate time in the header.
It is not advisable to use this in a short loop or the google server will soon identify you as a DDoS threat.
If you are behind the Great Chinese Firewall, you may have to change Google.com to Baidu.com, but in most places Google will have a close server with an accurate time in the header.
Code: Select all
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
print(string.sub(payload,string.find(payload,"Date: ")+6,string.find(payload,"Date: ")+35))
conn:close()
end)
conn:dns('google.com',function(conn,ip) ipaddr=ip end)
conn:connect(80,ipaddr)
heap = node.heap()
conn:send("HEAD / HTTP/1.1\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; ESP8266 NodeMcu Lua;)\r\n")
conn:send("\r\n")
It is not advisable to use this in a short loop or the google server will soon identify you as a DDoS threat.