capture-private-ip
v0.0.5
Published
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.
Downloads
6
Readme
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:
Open Chrome and in address bar type Chrome://flags
In the search box type Anonymize local IPs exposed by WebRTC
From the dropdown in result section, select the option Disabled
Open Edge and in address bar type edge://flags/
In the search box type Anonymize local IPs exposed by WebRTC
From the dropdown in result section, select the option Disabled
Open Firefox and in address bar type about:config
Click on Accept Risk and Continue
In the search bar type media.peerconnection.enabled and toggle it to set it true
In the search bar type media.peerconnection.ice.obfuscate_host_addresses and toggle it to set it to false
Open Internet Explorer 11.
Open Internet Options by clicking the gear icon localted in top right.
Click on Security tab.
Click on Intranet tab.
Click on Custom level button
Scroll to the setting Initialize and script ActiveX controls not marked safe for scripting.
Click the Enable button.
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.