是否可以使用打字稿而不使用第三方链接来获取公共IP地址 [英] is it possible to get public IP address using typescript without using third part links
本文介绍了是否可以使用打字稿而不使用第三方链接来获取公共IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我不是第一个提出这个问题的人,我正在Angular 4应用程序中工作,因此我需要使用我的系统(用户系统)的公共IP.
I know I am not the first to ask this question ,I am working in an Angular 4 application ,In this I need to take the public IP of my system(user system).
为此,我在Stackoverflow中搜索了参考,但是大多数文章都提供了使用第三方API url来获取IP的解决方案.
For that I have searched for the reference in Stackoverflow but most of the post gives the solution to consume third part API url for getting IP.
但就我而言,我想以编程方式跟踪用户系统的公共IP.
But in my case I want to programmatically trace the public IP of the user system.
我正在寻找建议或解决方案.
I am looking for the suggestions or solution in this.
推荐答案
您可以使用 public-ip
软件包.请注意,这在内部使用第三方服务器来确定您的公共IP地址,但至少已将其抽象出来.
import { Component, OnInit } from '@angular/core';
import publicIp from 'public-ip';
@Component({
selector: 'public-ip',
template: `<h1>Your public IP is {{publicIpAddr}}</h1>`
})
export class PublicIpComponent implements OnInit {
publicIpAddr: string;
ngOnInit() {
publicIp.v4().then((ip) => this.publicIpAddr = ip);
}
}
这篇关于是否可以使用打字稿而不使用第三方链接来获取公共IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文