Comparing version 0.1.0 to 0.1.1
var nat = exports; | ||
nat.utils = require('./nat-upnp/utils'); | ||
nat.ssdp = require('./nat-upnp/ssdp'); | ||
nat.device = require('./nat-upnp/device'); | ||
nat.createClient = require('./nat-upnp/client').create; |
@@ -47,2 +47,21 @@ var nat = require('../nat-upnp'); | ||
Client.prototype.externalIp = function externalIp(callback) { | ||
this.findGateway(function(err, gateway, address) { | ||
gateway.run('GetExternalIPAddress', [], function(err, data) { | ||
if (err) return callback(err); | ||
var key; | ||
Object.keys(data).some(function(k) { | ||
if (!/:GetExternalIPAddressResponse$/.test(k)) return false; | ||
key = k; | ||
return true; | ||
}); | ||
if (!key) return callback(Error('Incorrect response')); | ||
callback(null, data[key].NewExternalIPAddress); | ||
}); | ||
}); | ||
}; | ||
Client.prototype.findGateway = function findGateway(callback) { | ||
@@ -49,0 +68,0 @@ var ssdp = nat.ssdp.create(), |
@@ -1,2 +0,3 @@ | ||
var request = require('request'), | ||
var nat = require('../nat-upnp'), | ||
request = require('request'), | ||
url = require('url'), | ||
@@ -146,9 +147,17 @@ xml2js = require('xml2js'), | ||
if (err) return callback(err); | ||
if (res.statusCode !== 200) { | ||
return callback(Error('Request failed: ' + res.statusCode)); | ||
} | ||
callback(null); | ||
var parser = new xml2js.Parser(); | ||
parser.parseString(body, function(err, body) { | ||
if (res.statusCode !== 200) { | ||
return callback(Error('Request failed: ' + res.statusCode)); | ||
} | ||
var soapns = nat.utils.getNamespace( | ||
body, | ||
'http://schemas.xmlsoap.org/soap/envelope/'); | ||
callback(null, body[soapns + 'Body']); | ||
}); | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "nat-upnp", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "lib/nat-upnp", | ||
@@ -5,0 +5,0 @@ "author": "Fedor Indutny <fedor@indutny.com>", |
@@ -10,9 +10,7 @@ # NAT UPnP | ||
natUpnp.createClient().addMapping({ | ||
remote: { | ||
port: 12345 | ||
}, | ||
internal: { | ||
port: 54321 | ||
}, | ||
var client = natUpnp.createClient(); | ||
client.portMapping({ | ||
public: 12345 | ||
private: 54321, | ||
ttl: 10 | ||
@@ -22,2 +20,5 @@ }, function(err) { | ||
}); | ||
client.externalIp(function(err, ip) { | ||
}); | ||
``` | ||
@@ -24,0 +25,0 @@ |
var assert = require('assert'), | ||
net = require('net'), | ||
natUpnp = require('..'); | ||
@@ -10,3 +11,3 @@ | ||
it('should find router device', function(callback) { | ||
it('should add port mapping', function(callback) { | ||
c.portMapping({ | ||
@@ -21,2 +22,10 @@ public: ~~(Math.random() * 65536), | ||
}); | ||
it('should get external ip address', function(callback) { | ||
c.externalIp(function(err, ip) { | ||
assert.equal(err, null); | ||
assert(net.isIP(ip)); | ||
callback(); | ||
}); | ||
}); | ||
}); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
14184
10
384
48
2