Last active
December 11, 2015 00:38
-
-
Save hecomi/4517584 to your computer and use it in GitHub Desktop.
SOAP で Global IP をルーターから取得する奴
This file contains hidden or 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
var http = require('http'); | |
var data = '<?xml version="1.0"?>' + | |
'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' + | |
'<s:Body>' + | |
'<u:GetExternalIPAddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">' + | |
'</u:GetExternalIPAddress>' + | |
'</s:Body>' + | |
'</s:Envelope>'; | |
var options = { | |
host : '192.168.0.1', | |
port : 5432, | |
path : '/upnp/control/WANIPConn1', | |
method : 'POST', | |
headers: { | |
'Content-Type' : 'text/xml; charset=utf-8', | |
'Content-Length' : data.length, | |
'SOAPAction' : 'urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress' | |
} | |
}; | |
var req = http.request(options, function(res) { | |
console.log('STATUS: ' + res.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
// write data to request body | |
req.write(data); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment