0.0.5 • Published 4 years ago

capture-private-ip v0.0.5

Weekly downloads
15
License
-
Repository
-
Last release
4 years ago

Capture Private IP Address

This library helps you capture private IP address of the machine using WebRTC in modern browsers like Chrome, Firefox, Edge and machine name and user name in legacy browsers like Internet Explorer 11.

This library was generated with Angular CLI version 9.0.7.

Supported Browser Versions

Chrome >= 83.x

Edge >= 83.x

Firefox >= 76.x

Internet Explorer 11.x

How to Use

Install the package using the command given below:

npm install --save capture-private-ip

Include following Javascripts in scripts array in your project's angular.json file, like below:

"scripts": [
              "node_modules/capture-private-ip/src/js/ie-machine-name-finder.js",
              "node_modules/capture-private-ip/src/js/modern-ip-finder.js"
            ]

Include the module CapturePrivateIpModule in you App module like below:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {CapturePrivateIpModule} from 'capture-private-ip';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CapturePrivateIpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Inject and use the service CapturePrivateIpService in your App component like below:

import { Component, OnInit } from '@angular/core';
import { CapturePrivateIpService } from 'capture-private-ip';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'test-capture-private-ip-lib';
  machineDetails : any;
  allIps : any;

  constructor(private ipService:CapturePrivateIpService)
  {

  }

  ngOnInit()
  {
    const isIE = /msie\s|trident\//i.test(window.navigator.userAgent);
    const isEdge = /edg\//i.test(window.navigator.userAgent);
    const isChrome = /Chrome\//i.test(window.navigator.userAgent);
    const isFirefox = /Firefox\//i.test(window.navigator.userAgent);
    if(isIE)
      this.machineDetails = this.ipService.fetchMachineNameOnInternetExplorer();
    
    if(isEdge || isChrome || isFirefox)  {
      this.ipService.fetchPrivateIpOnModernBrowsers();
      setTimeout(()=>{
        this.allIps = document.cookie;
      },200);
    }
  }
}

You can render private IP captured in your App Component like below:

<div style="text-align:center">
  <h1>
    Welcome to {{ title }}!
  </h1>
  <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
  <div *ngIf="allIps">
    <pre>{{allIps}}</pre>
  </div>
  <div *ngIf="machineDetails">
    <pre>{{machineDetails.userName}}</pre>
    <pre>{{machineDetails.machineName}}</pre>
  </div>
</div>

Finally you need to set some browser flags/settings to disable annonymization of IP address and run ActiveX control:

  1. Open Chrome and in address bar type Chrome://flags
  2. In the search box type Anonymize local IPs exposed by WebRTC
  3. From the dropdown in result section, select the option Disabled

  4. Open Edge and in address bar type edge://flags/

  5. In the search box type Anonymize local IPs exposed by WebRTC
  6. From the dropdown in result section, select the option Disabled

  7. Open Firefox and in address bar type about:config

  8. Click on Accept Risk and Continue
  9. In the search bar type media.peerconnection.enabled and toggle it to set it true
  10. In the search bar type media.peerconnection.ice.obfuscate_host_addresses and toggle it to set it to false

  11. Open Internet Explorer 11.

  12. Open Internet Options by clicking the gear icon localted in top right.
  13. Click on Security tab.
  14. Click on Intranet tab.
  15. Click on Custom level button
  16. Scroll to the setting Initialize and script ActiveX controls not marked safe for scripting.
  17. Click the Enable button.
  18. Click Ok and come out.

Voila!! You are set to fetch private IPs and machine name on users machine where your site is being browsed.

Demo Private IP Capture

This Github repo demonstrates the use of this package.

Demo Private IP Capture

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago