Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Security Issues As Per GitHub Code Scanning Feature #20

Open
wants to merge 83 commits into
base: HEAD
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
7c16ec9
Adding cli files.
Aug 18, 2014
9d8c303
Added new dependency "node-getopt "
Aug 18, 2014
b4b9da8
Fixed cli parser module.
Aug 19, 2014
a076ec6
Moved cli to beta state.
Aug 19, 2014
55addbc
Fixed cli. Moved to working state.
Aug 19, 2014
2e2a9bd
Minor changes to output. Code cleanup.
Aug 19, 2014
cb5dbd1
That one extra new line.
Aug 19, 2014
09a1337
Minor fixes to info and renamed cli program.
Aug 19, 2014
e0bb080
Update README.md
Aug 19, 2014
28c242a
Update README.md
Aug 19, 2014
89ef790
Merge branch 'pr/3'
J-Chaniotis Aug 26, 2014
749c838
Revert "Merge branch 'pr/3'"
J-Chaniotis Aug 26, 2014
3ddf0fd
manual merge cli
J-Chaniotis Aug 26, 2014
217515c
update docs
J-Chaniotis Aug 26, 2014
08be719
0.2.0
J-Chaniotis Aug 26, 2014
b8c6827
minor documentation changes
J-Chaniotis Aug 26, 2014
1e20c01
0.3.0
J-Chaniotis Aug 26, 2014
1896bbb
0.2.1
J-Chaniotis Aug 26, 2014
336b346
fix readme
J-Chaniotis Aug 27, 2014
1e0f4aa
0.2.2
J-Chaniotis Aug 27, 2014
515e397
pointless keyword
J-Chaniotis Aug 27, 2014
c8efc60
Removed asyncLoop from utils
J-Chaniotis Aug 28, 2014
2e36cb1
0.2.3
J-Chaniotis Aug 28, 2014
b6dfb1c
add OpenDNS
gblazex Oct 11, 2015
8dea39f
Merge pull request #5 from galambalazs/patch-1
J-Chaniotis Oct 11, 2015
4a65f7b
Replace all instances of ifconfig.me with ifconfig.io
georgyo Oct 24, 2015
00585cb
Merge pull request #6 from georgyo/master
J-Chaniotis Oct 25, 2015
27a3be8
Update dependencies. Add node 4.2.1 to travis
Oct 25, 2015
af0f154
0.2.4
Oct 25, 2015
9807342
add node 6.5.0 to travis
JLHwung Aug 31, 2016
fa743df
Merge pull request #10 from JLHwung/patch-2
J-Chaniotis Aug 31, 2016
3f6c636
all around maintenance, in progress
Jun 17, 2017
3d38907
all around maintenance, remove one dependency
Jun 18, 2017
4a92b97
all around maintenance
Jun 18, 2017
06dc15c
all around maintenance
Jun 18, 2017
0a4acb6
all around maintenance
Jun 18, 2017
4cb16f1
remove 4.8.3 and 5.12.0 from travis
Jun 18, 2017
58df623
1.0.0
Jun 18, 2017
f3ec7df
add -V to cli
Jun 19, 2017
3ebd913
1.0.1
Jun 19, 2017
2dd46bf
fix request context
Jun 20, 2017
fa09a58
Use simple-request instead of request
Jun 20, 2017
69528ed
1.1.0
Jun 20, 2017
4201b6f
CLI sugar
Jun 23, 2017
9fde908
Add user agent as an option, some polishing
Jun 23, 2017
6d005ed
1.2.0
Jun 23, 2017
3757550
Update README.md
J-Chaniotis Jun 24, 2017
8266a0d
Update README.md
J-Chaniotis Jun 24, 2017
8fd6a5d
1.2.1
Jun 24, 2017
a73ac49
Add verbose mode so you know where that IP came from
Jun 25, 2017
f7cf733
1.3.0
Jun 25, 2017
3ab4336
update example with promises
Jun 25, 2017
de8a323
Update README.md
J-Chaniotis Jun 25, 2017
8202b7f
1.3.1
Jun 25, 2017
47d6249
Replace revalidator with ajv. Lots of refactoring.
Mar 8, 2018
26ca2d2
Added more tests.
Mar 9, 2018
09d7bce
Debug the tests in travis
Mar 9, 2018
3ca0751
fix travis-ci IP mismatch error
Mar 9, 2018
3116e16
update dependencies
Mar 9, 2018
cb9e5df
fix cli parallel option
Mar 9, 2018
f119abb
2.0.0
Mar 9, 2018
11fd148
update ajv :/
Mar 9, 2018
554b39f
2.0.1
Mar 9, 2018
2a6ef13
update dev-dependencies
Mar 9, 2018
ea00033
2.0.2
Mar 9, 2018
12a01df
Move from jshint to eslint
Mar 11, 2018
6ddc0aa
2.0.3
Mar 11, 2018
214b723
Small fixes to README and add a new provider.
Oct 31, 2018
57eb479
Bump version.
Oct 31, 2018
4edda92
Updated dependencies and refactored failing test.
N-Andronopoulos Oct 31, 2018
0cdc779
Added more envs.
N-Andronopoulos Oct 31, 2018
93060d2
Refactored test to run on both Windows and Linux.
N-Andronopoulos Oct 31, 2018
ec2336e
Forgot else statement.
N-Andronopoulos Oct 31, 2018
9a17467
Merge pull request #14 from UmanShahzad/uman/readme-and-ipinfo
J-Chaniotis Nov 24, 2018
0a16a02
Merge branch 'master' into OgMaster
J-Chaniotis Nov 24, 2018
d89caf2
Merge pull request #15 from N-Andronopoulos/OgMaster
J-Chaniotis Nov 24, 2018
565df1a
* Update dependencies
Apr 26, 2020
7f87e80
2.2.0
Apr 26, 2020
1cbad65
*Remove old node versions from travis
Apr 26, 2020
8d1a2d3
2.3.0
Apr 26, 2020
8a035a4
remove https://tnx.nl/ip from default config due to timeouts
Apr 26, 2020
7251c49
2.3.1
Apr 26, 2020
dce774f
Update ajv & simple-get Version
Capta1nRaj Oct 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017
},
"rules": {
"no-console": "off",
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
28 changes: 0 additions & 28 deletions .jshintrc

This file was deleted.

7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "8.4.0"
- "9.8.0"
- "10.13.0"
- "11.0.0"
- "13.13.0"
144 changes: 117 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,169 @@
#external-ip [![Build Status](https://travis-ci.org/J-Chaniotis/external-ip.svg?branch=master)](https://travis-ci.org/J-Chaniotis/external-ip) [![Dependency Status](https://david-dm.org/J-Chaniotis/external-ip.svg)](https://david-dm.org/J-Chaniotis/external-ip)

![XKCD 865](http://imgs.xkcd.com/comics/nanobots.png)
# external-ip

[![Build Status](https://travis-ci.org/J-Chaniotis/external-ip.svg?branch=master)](https://travis-ci.org/J-Chaniotis/external-ip)
[![Dependency Status](https://david-dm.org/j-Chaniotis/external-ip.svg)](https://david-dm.org/j-Chaniotis/external-ip)
[![npm version](https://badge.fury.io/js/external-ip.svg)](https://badge.fury.io/js/external-ip)

![XKCD 865](http://imgs.xkcd.com/comics/nanobots.png)

`external-ip` is a node.js library to get your external ip from multiple services.



##Installation
## Installation

`npm install external-ip`

##Usage
## Usage

basic

```javascript
'use strict';

var getIP = require('external-ip')();
const getIP = require('external-ip')();

getIP(function (err, ip) {
getIP((err, ip) => {
if (err) {
// every service in the list has failed
throw err;
}
console.log(ip);
});

```

with configuration

```javascript
'use strict';

var extIP = require('external-ip');
const extIP = require('external-ip');

var getIP = extIP({
let getIP = extIP({
replace: true,
services: ['http://ifconfig.co/x-real-ip', 'http://ifconfig.me/ip'],
services: ['https://ipinfo.io/ip', 'http://ifconfig.co/x-real-ip', 'http://ifconfig.io/ip'],
timeout: 600,
getIP: 'parallel'
getIP: 'parallel',
userAgent: 'Chrome 15.0.874 / Mac OS X 10.8.1'
});

getIP(function (err, ip) {
getIP((err, ip) => {
if (err) {
throw err;
}
console.log(ip);
});
```

### Promises

The API of this library is designed around the classic node.js error-first callback.
As of node.js V8, converting this type of callback into a promise is pretty straight forward and
requires one more line of code.

basic

```javascript
'use strict';

const {promisify} = require('util'); //<-- Require promisify
const getIP = promisify(require('external-ip')()); // <-- And then wrap the library

getIP().then((ip)=> {
console.log(ip);
}).catch((error) => {
console.error(error);
});
```

with configuration

```javascript
'use strict';
const { promisify } = require('util'); //<-- Require promisify
const getIP = promisify(require('external-ip')({
replace: true,
services: ['https://ipinfo.io/ip', 'http://icanhazip.com/', 'http://ident.me/'],
timeout: 600,
getIP: 'parallel',
verbose: true
})); // <-- And then wrap the library

getIP().then((ip) => {
console.log(ip);
}).catch((error) => {
console.error(error);
});
```
##extIP([config])
external-ip exposes a constructor function that accepts a configuration object with the following optional properties:
* **services:** `Array` of urls that return the ip in the document body, required if replace is set to true

If you believe this extra step shouldn't be there, feel free to open an issue and/or a pull request.

## Configuration

### extIP([config])

`require('external-ip')` returns a constructor function that accepts an optional configuration object.
It can be used to create multiple instances with different configuration if necessary

* **services:** `Array` of urls that return the ip in the html body, required if replace is set to true
* **replace:** `Boolean` if true, replaces the internal array of services with the user defined, if false, extends it, default: `false`
* **timeout:** Timeout per request in ms, default `500`
* **getIP:** `'sequential'` Sends a request to the first url in the list, if that fails sends to the next and so on. `'parallel'` Sends requests to all the sites in the list, on the first valid response all the pending requests are canceled. default: `'sequential'`
* **timeout:** Timeout per request in ms, default `1000`
* **getIP:** `'sequential'` Makes a request to the first url in the list, if that fails sends to the next and so on. `'parallel'` Makes requests to all the sites in the list, on the first valid response all the pending requests are canceled, default: `'sequential'`
* **userAgent:** `String` Set a custom `User-Agent` header, default: `curl/`
* **verbose:** `Boolean` Log additional information to the console, default: `false`

Returns the configured getIP function.
Returns the configured getIP instance.

### getIP(callback)

##getIP(callback)
The callback gets 2 arguments:

1. error: if every service in the list fails to return a valid ip
2. ip: your external ip

##Test
## CLI

install as a global package with `npm install -g external-ip`.

```bash
$ external-ip -h

Usage: external-ip [options]

Options:

-h, --help output usage information
-V, --version output the version number
-R, --replace replace internal services instead of extending them.
-s, --services <url> service url, see examples, required if using -R
-t, --timeout <ms> set timeout per request
-P, --parallel set to parallel mode
-u, --userAgent <User-Agent> provide a User-Agent header, default: curl/
-v, --verbose provide additional details


This program prints the external IP of the machine.
All arguments are optional.

Examples:
$ external-ip
$ external-ip -P -t 1500 -R -s http://icanhazip.com/ -s http://ident.me/

Default services:
http://icanhazip.com/
http://ident.me/
http://tnx.nl/ip
http://myip.dnsomatic.com/
http://ipecho.net/plain
http://diagnostic.opendns.com/myip

Documentation can be found at https://github.com/J-Chaniotis/external-ip
```

## Test

Change your working directory to the project's root, `npm install` to get the development dependencies and then run `npm test`

##Todo
maybe a CLI
## Links

##Links
* [moira](https://www.npmjs.org/package/moira)
* [externalip](https://www.npmjs.org/package/externalip)
* [extip](https://www.npmjs.org/package/extip)
* [extip](https://www.npmjs.org/package/extip)
6 changes: 3 additions & 3 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

var getIP = require('../index')();
const getIP = require('../index')();

getIP(function (err, ip) {
getIP((err, ip) => {
if (err) {
throw err;
}
console.log(ip);
});
});
10 changes: 5 additions & 5 deletions examples/customConfig.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

var extIP = require('../index');
const extIP = require('../index');

var getIP = extIP({
const getIP = extIP({
replace: true, // true: replace the default services list, false: extend it, default: false
services: ['http://ifconfig.co/x-real-ip', 'http://ifconfig.me/ip'],
services: ['https://ipinfo.io/ip', 'http://icanhazip.com/', 'http://ident.me/'],
timeout: 600, // set timeout per request, default: 500ms
'getIP': 'parallel'
getIP: 'parallel'
});

getIP(function (err, ip) {
getIP((err, ip) => {
if (err) {
throw err;
}
Expand Down
9 changes: 9 additions & 0 deletions examples/promiseBasic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';
const {promisify} = require('util');
const getIP = promisify(require('../index')());

getIP().then((ip)=> {
console.log(ip);
}).catch((error) => {
console.error(error);
});
15 changes: 15 additions & 0 deletions examples/promiseCustomConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const { promisify } = require('util');
const getIP = promisify(require('../index')({
replace: true, // true: replace the default services list, false: extend it, default: false
services: ['https://ipinfo.io/ip', 'http://icanhazip.com/', 'http://ident.me/'],
timeout: 600, // set timeout per request, default: 500ms
getIP: 'parallel',
verbose: true
}));

getIP().then((ip) => {
console.log(ip);
}).catch((error) => {
console.error(error);
});
Loading