#!/usr/local/bin/ruby # # NEC DL180V用グローバルIP取得スクリプト # # require 'net/http' #更新 def update() Net::HTTP.start('free.ddo.jp',80){|http| response = http.get('/dnsupdate.php?dn=XXXXXX&pw=XXXXX') } end Net::HTTP.version_1_2 req = Net::HTTP::Get.new('/index.cgi/info_now_com_show') req.basic_auth 'adm', 'root' #DL180Vのパスワード Net::HTTP.start('192.168.0.1') {|http| response = http.request(req) i = response.body.index("WAN側のIPアドレス/ネットマスクを表示します") i = response.body.index("",i) e= response.body.index("/",i) ip = response.body[i+8..e-1] #ipアドレス取得 # puts ip; file = File.open("./adr",'r') add = file.gets file.close if(add != ip) #ipアドレスが違う file = File.open("./adr",'w') file.print ip file.close update() #更新 end } #end of file