【问题标题】:Whois Lookup in CSVCSV 中的 Whois 查找
【发布时间】:2021-11-29 09:32:37
【问题描述】:

我有大约 9000 个 IP,需要存储这些数据以用于研究目的。 我正在尝试通过 whois 命令将这些 IP 数据存储在 CSV 文件中

我正在寻找:第一行应该是仅标题,(我也可以手动执行),第二行必须包含一行输出(我卡在这里)。

我的代码:

while read -r ip; do

whois $ip | grep : | tr -d : | rs -T | tr -s ' ' , >> output.csv

done < "ip.txt"

通过上面的命令,数据是一个存储,但是是多行的。

样本输出

%   refer   status  %   -   Co. Ltd.    CN  ALLOCATED   last-modified   China   IP50-AP CNNIC   remarks remarks the role    phone   nic-hdl abuse-mailbox   person  District    Beijing lwz@knet.cn APNIC   Zhongguancun    Haidian e-mail  source  Co. Ltd.    MAINT-CNNIC-AP
for whois.apnic.net ALLOCATED   Whois   1.8.255.255 descr   admin-c PORTABLE    2021-06-16T013150Z  e-mail  auth    is  empowered   Please  network.    ABUSE   0   AC1601-AP   ipas@cnnic.cn   Wenzhe  country nic-hdl person  District    Beijing xingzhijie@knet.cn  APNIC   country last-modified           
more    inetnum whois   data    netname 4   South   ZX2975-AP   mnt-by  source  ipas@cnnic.cn   #   not to  contact mnt-by  CNNICCN e-mail  remarks mnt-by  Lu  CN  WL1818-AP   Zhijie  country nic-hdl route   CN  2011-06-29T014602Z          
information 1.0.0.0 whois.apnic.net copyright   KNET    4th tech-c  MAINT-CNNIC-AP  APNIC   abuse-mailbox   Filtered    an  investigate the MAINT-CNNIC-AP  address ipas@cnnic.cn   Generated   APNIC-ABUSE address phone   mnt-by  Xing    CN  ZX2975-AP   1.8.0.0/16  origin  source              
on  -   changed terms   descr   treet   WL1818-AP   mnt-routes  irt ipas@cnnic.cn   remarks ISP complaints  tech-c  last-modified   Beijing admin-c from    last-modified   4   South   -58812941   MAINT-CNNIC-AP  address phone   mnt-by  descr   AS38345 APNIC           
IANA    1.255.255.255   2010-01 http//www.apnic.net/db/dbcopyright.html KNET    Zhongguancun    Haidian abuse-c MAINT-CNNIC-AP  IRT-CNNIC-CN    admin-c Please  and of  or  2021-06-16T013957Z  China   IP50-AP irt 2020-05-14T111901Z  4th fax-no  last-modified   4   South   -58812398   MAINT-CNNIC-AP  KNET    notify          
visit   organisation    source  inetnum Techonlogy  District    Beijing AC1601-AP   mnt-irt address IP50-AP note    is  network admin-c source  country tech-c  object  source  treet   -58812716   2011-03-16T033202Z  4th fax-no  last-modified   Techonlogy  lwz@knet.cn             
http//www.iana.org  APNIC   IANA    1.8.19.0    (BeiJing)   country status  IRT-CNNIC-CN    Beijing tech-c  that    not abuse.  of  APNIC   ZZ  IP50-AP IRT-CNNIC-CN    APNIC   Zhongguancun    Haidian e-mail  source  treet   -58812716   2014-07-23T030801Z  (BeiJing)   mnt-by              
%   refer   status  %   -   Co. Ltd.    CN  ALLOCATED   last-modified   China   IP50-AP CNNIC   remarks remarks the role    phone   nic-hdl abuse-mailbox   person  District    Beijing lwz@knet.cn APNIC   Zhongguancun    Haidian e-mail  source  Co. Ltd.    MAINT-CNNIC-AP
for whois.apnic.net ALLOCATED   Whois   1.8.255.255 descr   admin-c PORTABLE    2021-06-16T013150Z  e-mail  auth    is  empowered   Please  network.    ABUSE   0   AC1601-AP   ipas@cnnic.cn   Wenzhe  country nic-hdl person  District    Beijing xingzhijie@knet.cn  APNIC   country last-modified           
more    inetnum whois   data    netname 4   South   ZX2975-AP   mnt-by  source  ipas@cnnic.cn   #   not to  contact mnt-by  CNNICCN e-mail  remarks mnt-by  Lu  CN  WL1818-AP   Zhijie  country nic-hdl route   CN  2011-06-29T014602Z          
information 1.0.0.0 whois.apnic.net copyright   KNET    4th tech-c  MAINT-CNNIC-AP  APNIC   abuse-mailbox   Filtered    an  investigate the MAINT-CNNIC-AP  address ipas@cnnic.cn   Generated   APNIC-ABUSE address phone   mnt-by  Xing    CN  ZX2975-AP   1.8.0.0/16  origin  source              
on  -   changed terms   descr   treet   WL1818-AP   mnt-routes  irt ipas@cnnic.cn   remarks ISP complaints  tech-c  last-modified   Beijing admin-c from    last-modified   4   South   -58812941   MAINT-CNNIC-AP  address phone   mnt-by  descr   AS38345 APNIC           
IANA    1.255.255.255   2010-01 http//www.apnic.net/db/dbcopyright.html KNET    Zhongguancun    Haidian abuse-c MAINT-CNNIC-AP  IRT-CNNIC-CN    admin-c Please  and of  or  2021-06-16T013957Z  China   IP50-AP irt 2020-05-14T111901Z  4th fax-no  last-modified   4   South   -58812398   MAINT-CNNIC-AP  KNET    notify          
visit   organisation    source  inetnum Techonlogy  District    Beijing AC1601-AP   mnt-irt address IP50-AP note    is  network admin-c source  country tech-c  object  source  treet   -58812716   2011-03-16T033202Z  4th fax-no  last-modified   Techonlogy  lwz@knet.cn             
http//www.iana.org  APNIC   IANA    1.8.19.0    (BeiJing)   country status  IRT-CNNIC-CN    Beijing tech-c  that    not abuse.  of  APNIC   ZZ  IP50-AP IRT-CNNIC-CN    APNIC   Zhongguancun    Haidian e-mail  source  treet   -58812716   2014-07-23T030801Z  (BeiJing)   mnt-by              

ip.txt

1.8.65.98
1.8.65.99
1.8.65.92
1.82.15.99
11.18.65.19
111.8.65.99
1.18.65.91
1.81.65.99
1.8.15.99
1.8.61.99



 

【问题讨论】:

    标签: bash awk sed grep tr


    【解决方案1】:
    whois 1.1.1.1 | grep ": " | awk -F": " '{print $1}' | tr '\n' ','  >> result.csv
    
    while read -r ip; do
    
    wip=$(whois $ip | grep ": " | awk -F": " '{print $2}' | tr '\n' ',' )
    
    echo $ip,$wip >> result.csv
    
    done < "ip.txt"
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    • 在使用 awk 时,您永远不需要 greptr,除非您不需要使用它,否则您应该始终在 shell while-read 循环中使用 IFS=,并且您应该除非你不需要引用它们,否则总是引用你的 shell 变量。
    猜你喜欢
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2020-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多