简体   繁体   English

仅返回部分 Whois 信息

[英]return only part of Whois information

Hi we are trying to use NodeJS to return IP address WHOIS information before we send the requesting IP address to the rest of our app - That part is easy.嗨,在我们将请求的 IP 地址发送到我们应用程序的 rest 之前,我们正在尝试使用 NodeJS 返回 IP 地址 WHOIS 信息 - 这部分很简单。

However the part that is not easy is, selecting only the Organization part of the whois information.然而,不容易的部分是,只选择 WHOIS 信息的Organization部分。

for example this is a whois and what it returns例如,这是一个 whois 及其返回的内容

whois 137.184.236.168
% IANA WHOIS server
% for more information on IANA, visit http://www.iana.org
% This query returned 1 object

refer:        whois.arin.net

inetnum:      137.0.0.0 - 137.255.255.255
organisation: Administered by ARIN
status:       LEGACY

whois:        whois.arin.net

changed:      1993-05
source:       IANA

# whois.arin.net

NetRange:       137.184.0.0 - 137.184.255.255
CIDR:           137.184.0.0/16
NetName:        DIGITALOCEAN-137-184-0-0
NetHandle:      NET-137-184-0-0-1
Parent:         NET137 (NET-137-0-0-0-0)
NetType:        Direct Allocation
OriginAS:       AS14061
Organization:   DigitalOcean, LLC (DO-13)
RegDate:        2019-11-13
Updated:        2020-04-03
Comment:        Routing and Peering Policy can be found at https://www.as14061.net
Comment:        
Comment:        Please submit abuse reports at https://www.digitalocean.com/company/contact/#abuse
Ref:            https://rdap.arin.net/registry/ip/137.184.0.0



OrgName:        DigitalOcean, LLC
OrgId:          DO-13
Address:        101 Ave of the Americas
Address:        FL2
City:           New York
StateProv:      NY
PostalCode:     10013
Country:        US
RegDate:        2012-05-14
Updated:        2022-05-19
Ref:            https://rdap.arin.net/registry/entity/DO-13


OrgAbuseHandle: ABUSE5232-ARIN
OrgAbuseName:   Abuse, DigitalOcean 
OrgAbusePhone:  +1-347-875-6044 
OrgAbuseEmail:  abuse@digitalocean.com
OrgAbuseRef:    https://rdap.arin.net/registry/entity/ABUSE5232-ARIN

OrgTechHandle: NOC32014-ARIN
OrgTechName:   Network Operations Center
OrgTechPhone:  +1-347-875-6044 
OrgTechEmail:  noc@digitalocean.com
OrgTechRef:    https://rdap.arin.net/registry/entity/NOC32014-ARIN

OrgNOCHandle: NOC32014-ARIN
OrgNOCName:   Network Operations Center
OrgNOCPhone:  +1-347-875-6044 
OrgNOCEmail:  noc@digitalocean.com
OrgNOCRef:    https://rdap.arin.net/registry/entity/NOC32014-ARIN

The only thing we are interested in is Organization: DigitalOcean, LLC (DO-13)我们唯一感兴趣的是Organization: DigitalOcean, LLC (DO-13)

As we want to drop all IP addresses from this host provider.因为我们想从这个主机提供商中删除所有 IP 地址。

We noticed that we have been successful at stopping Google and AWS via using host command but Digital Ocean does not work this way and we need to do it via Whois.我们注意到,我们已经通过使用host命令成功地阻止了 Google 和 AWS,但 Digital Ocean 不能以这种方式工作,我们需要通过 Whois 来完成。

I know in NodeJS I would request the information我知道在 NodeJS 中我会请求信息

 exec("whois "+ip, (error, stdout, stderr) => {
    console.log(stdout);
  }

Could use a regular expression:可以使用正则表达式:

const organizationPattern = /^organization:\s*(.+)$/im;
const match = organizationPattern.exec(stdout);
const organization = match ? match[1] : 'unknown';

console.log(organization);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM