Created
April 23, 2017 11:46
-
-
Save zinntikumugai/0b4599d297c369714635dfbd9a382072 to your computer and use it in GitHub Desktop.
[Lua]DDNSの更新スクリプト(未完成)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
urltable = { | |
--hostname directory UseIPaddress | |
{"www.mydns.jp", "/directip.html?MID=mydnsxxxxxx&PWD=xxxxxxxxxxx&IPV4ADDR=",true}, | |
{"f5.si", "/update.php?domain=xxxxxxxxx&password=xxxxxxxxxx", false} | |
} | |
-- http://symfoware.blog68.fc2.com/blog-entry-455.html | |
function split(str, delim) | |
if string.find(str, delim) == nil then | |
return {str} | |
end | |
local result = {} | |
local pat = "(,-)" ..delim .."()" | |
local lastPos | |
for part, pos in string.gfind(str,pat) do | |
table.insert( result, part ) | |
lastPos = pos | |
end | |
table.insert( result, string.sub(str, lastPos)) | |
return result | |
end | |
-- | |
data='' | |
ip='' | |
function urlget( host, directory, agent, mode) | |
conn = net.createConnection( net.TCP, false ) | |
conn:on( | |
"receive", | |
function( conns, pl ) | |
print("\n---", host, directory, agent, mode, "---\n") | |
if mode == "ip" then | |
data = pl | |
for i, val in ipairs( split( data ,"\r\n")) do | |
ip = val | |
end | |
ip = string.sub( ip, 0, string.len(ip)-1 ) | |
print("IP: " ..ip ) | |
for i, value in ipairs( urltable ) do | |
if value[3] == true then | |
access = value[2] ..ip | |
else | |
access = value[2] | |
end | |
urlget( value[1], access, "ZinLion(ESP8266; Lua;)" ,"") | |
--print (value[1], access, "ZinLion(ESP8266; Lua;)" ,"") | |
print('B') | |
end | |
else | |
print("-------------------------") | |
print( pl ) | |
print("-------------------------") | |
--uart.setup(0,115200,8,0,1,1) | |
end | |
end | |
) | |
conn:on( | |
"connection", | |
function( c ) | |
-- print("conected") | |
connsendd = "GET " ..directory .." HTTP/1.1\r\n" | |
.."Host: " ..host .."\r\n" | |
.."Accept: " .."/" .."\r\n" | |
.."Accept-Language: " .."ja-jp" .."\r\n" | |
.."User-Agent: " ..agent .."\r\n" | |
.."\r\n" | |
print(connsendd) | |
conn:send(connsendd) | |
end | |
) | |
conn:connect(80, host) | |
end | |
urlget( "ifconfig.io", "/", "curl/7.29.0", "ip" ) | |
-- for i , value in ipairs(urltable) do | |
-- print( value ) | |
-- end | |
-- "ZinLion(ESP8266; Lua;)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment