whois

 

 

import 'dart:io';
import 'dart:convert';

main()async{
  List a = ['1.cn','2.cn','3.cn','4.cn','5.cn','6.cn','7.cn','8.cn','9.cn','10.cn','11.cn','12.cn','13.cn','14.cn','15.cn','16.cn','17.cn','18.cn','19.cn','20.cn','21.cn','22.cn','23.cn','24.cn','25.cn','26.cn','27.cn','28.cn','29.cn','30.cn','31.cn','32.cn','33.cn','34.cn','35.cn','36.cn','37.cn','38.cn','39.cn','40.cn','41.cn','42.cn','43.cn','44.cn','45.cn','46.cn','47.cn','48.cn','49.cn','50.cn','51.cn','52.cn','53.cn','54.cn','55.cn','56.cn','57.cn','58.cn','59.cn','60.cn','61.cn','62.cn','63.cn','64.cn','65.cn','66.cn','67.cn','68.cn','69.cn','70.cn','71.cn','72.cn','73.cn','74.cn','75.cn','76.cn','77.cn','78.cn','79.cn','80.cn','81.cn','82.cn','83.cn','84.cn','85.cn','86.cn','87.cn','88.cn','89.cn','90.cn','91.cn','92.cn','93.cn','94.cn','95.cn','96.cn','97.cn','98.cn','99.cn','100.cn','101.cn','102.cn','103.cn','104.cn','105.cn','106.cn','107.cn','108.cn','109.cn','110.cn','111.cn','112.cn','113.cn','114.cn','115.cn','116.cn','117.cn','118.cn','119.cn','120.cn','121.cn','122.cn','123.cn','124.cn','125.cn','126.cn','127.cn','128.cn','129.cn','130.cn','131.cn','132.cn','133.cn','134.cn','135.cn','136.cn','137.cn','138.cn','139.cn','140.cn','141.cn','142.cn','143.cn','144.cn','145.cn','146.cn','147.cn','148.cn','149.cn','150.cn','151.cn','152.cn','153.cn','154.cn','155.cn','156.cn','157.cn','158.cn','159.cn','160.cn','161.cn','162.cn','163.cn','164.cn','165.cn','166.cn','167.cn','168.cn','169.cn','170.cn','171.cn','172.cn','173.cn','174.cn','175.cn','176.cn','177.cn','178.cn','179.cn','180.cn','181.cn','182.cn','183.cn','184.cn','185.cn','186.cn','187.cn','188.cn','189.cn','190.cn','191.cn','192.cn','193.cn','194.cn','195.cn','196.cn','197.cn','198.cn','199.cn','200.cn','201.cn','202.cn','203.cn','204.cn','205.cn','206.cn','207.cn','208.cn','209.cn','210.cn','211.cn','212.cn','213.cn','214.cn','215.cn','216.cn','217.cn','218.cn','219.cn','220.cn','221.cn','222.cn','223.cn','224.cn','225.cn','226.cn','227.cn','228.cn','229.cn','230.cn','231.cn','232.cn','233.cn','234.cn','235.cn','236.cn','237.cn','238.cn','239.cn','240.cn','241.cn','242.cn','243.cn','244.cn','245.cn','246.cn','247.cn','248.cn','249.cn','250.cn','251.cn','252.cn','253.cn','254.cn','255.cn','256.cn','257.cn','258.cn','259.cn','260.cn','261.cn','262.cn','263.cn','264.cn','265.cn','266.cn','267.cn','268.cn','269.cn','270.cn','271.cn','272.cn','273.cn','274.cn','275.cn','276.cn','277.cn','278.cn','279.cn','280.cn','281.cn','282.cn','283.cn','284.cn','285.cn','286.cn','287.cn','288.cn','289.cn','290.cn','291.cn','292.cn','293.cn','294.cn','295.cn','296.cn','297.cn','298.cn','299.cn','300.cn','301.cn','302.cn','303.cn','304.cn','305.cn','306.cn','307.cn','308.cn','309.cn','310.cn','311.cn','312.cn','313.cn','314.cn','315.cn','316.cn','317.cn','318.cn','319.cn','320.cn','321.cn','322.cn','323.cn','324.cn','325.cn','326.cn','327.cn','328.cn','329.cn','330.cn','331.cn','332.cn','333.cn','334.cn','335.cn','336.cn','337.cn','338.cn','339.cn','340.cn','341.cn','342.cn','343.cn','344.cn','345.cn','346.cn','347.cn','348.cn','349.cn','350.cn','351.cn','352.cn','353.cn','354.cn','355.cn','356.cn','357.cn','358.cn','359.cn','360.cn','361.cn','362.cn','363.cn','364.cn','365.cn','366.cn','367.cn','368.cn','369.cn','370.cn','371.cn','372.cn','373.cn','374.cn','375.cn','376.cn','377.cn','378.cn','379.cn','380.cn','381.cn','382.cn','383.cn','384.cn','385.cn','386.cn','387.cn','388.cn','389.cn','390.cn','391.cn','392.cn','393.cn','394.cn','395.cn','396.cn','397.cn','398.cn','399.cn','400.cn','401.cn','402.cn','403.cn','404.cn','405.cn','406.cn','407.cn','408.cn','409.cn','410.cn','411.cn','412.cn','413.cn','414.cn','415.cn','416.cn','417.cn','418.cn','419.cn','420.cn','421.cn','422.cn','423.cn','424.cn','425.cn','426.cn','427.cn','428.cn','429.cn','430.cn','431.cn','432.cn','433.cn','434.cn','435.cn','436.cn','437.cn','438.cn','439.cn','440.cn','441.cn','442.cn','443.cn','444.cn','445.cn','446.cn','447.cn','448.cn','449.cn','450.cn','451.cn','452.cn','453.cn','454.cn','455.cn','456.cn','457.cn','458.cn','459.cn','460.cn','461.cn','462.cn','463.cn','464.cn','465.cn','466.cn','467.cn','468.cn','469.cn','470.cn','471.cn','472.cn','473.cn','474.cn','475.cn','476.cn','477.cn','478.cn','479.cn','480.cn','481.cn','482.cn','483.cn','484.cn','485.cn','486.cn','487.cn','488.cn','489.cn','490.cn','491.cn','492.cn','493.cn','494.cn','495.cn','496.cn','497.cn','498.cn','499.cn','500.cn','501.cn','502.cn','503.cn','504.cn','505.cn','506.cn','507.cn','508.cn','509.cn','510.cn','511.cn','512.cn','513.cn','514.cn','515.cn','516.cn','517.cn','518.cn','519.cn','520.cn','521.cn','522.cn','523.cn','524.cn','525.cn','526.cn','527.cn','528.cn','529.cn','530.cn','531.cn','532.cn','533.cn','534.cn','535.cn','536.cn','537.cn','538.cn','539.cn','540.cn','541.cn','542.cn','543.cn','544.cn','545.cn','546.cn','547.cn','548.cn','549.cn','550.cn','551.cn','552.cn','553.cn','554.cn','555.cn','556.cn','557.cn','558.cn','559.cn','560.cn','561.cn','562.cn','563.cn','564.cn','565.cn','566.cn','567.cn','568.cn','569.cn','570.cn','571.cn','572.cn','573.cn','574.cn','575.cn','576.cn','577.cn','578.cn','579.cn','580.cn','581.cn','582.cn','583.cn','584.cn','585.cn','586.cn','587.cn','588.cn','589.cn','590.cn','591.cn','592.cn','593.cn','594.cn','595.cn','596.cn','597.cn','598.cn','599.cn','600.cn','601.cn','602.cn','603.cn','604.cn','605.cn','606.cn','607.cn','608.cn','609.cn','610.cn','611.cn','612.cn','613.cn','614.cn','615.cn','616.cn','617.cn','618.cn','619.cn','620.cn','621.cn','622.cn','623.cn','624.cn','625.cn','626.cn','627.cn','628.cn','629.cn','630.cn','631.cn','632.cn','633.cn','634.cn','635.cn','636.cn','637.cn','638.cn','639.cn','640.cn','641.cn','642.cn','643.cn','644.cn','645.cn','646.cn','647.cn','648.cn','649.cn','650.cn','651.cn','652.cn','653.cn','654.cn','655.cn','656.cn','657.cn','658.cn','659.cn','660.cn','661.cn','662.cn','663.cn','664.cn','665.cn','666.cn','667.cn','668.cn','669.cn','670.cn','671.cn','672.cn','673.cn','674.cn','675.cn','676.cn','677.cn','678.cn','679.cn','680.cn','681.cn','682.cn','683.cn','684.cn','685.cn','686.cn','687.cn','688.cn','689.cn','690.cn','691.cn','692.cn','693.cn','694.cn','695.cn','696.cn','697.cn','698.cn','699.cn','700.cn','701.cn','702.cn','703.cn','704.cn','705.cn','706.cn','707.cn','708.cn','709.cn','710.cn','711.cn','712.cn','713.cn','714.cn','715.cn','716.cn','717.cn','718.cn','719.cn','720.cn','721.cn','722.cn','723.cn','724.cn','725.cn','726.cn','727.cn','728.cn','729.cn','730.cn','731.cn','732.cn','733.cn','734.cn','735.cn','736.cn','737.cn','738.cn','739.cn','740.cn','741.cn','742.cn','743.cn','744.cn','745.cn','746.cn','747.cn','748.cn','749.cn','750.cn','751.cn','752.cn','753.cn','754.cn','755.cn','756.cn','757.cn','758.cn','759.cn','760.cn','761.cn','762.cn','763.cn','764.cn','765.cn','766.cn','767.cn','768.cn','769.cn','770.cn','771.cn','772.cn'];

  for(int i=0; i<a.length; i++){
    Whois w = Whois(domain: a[i]);
    await w.getWhois();
  }
}




class Whois{
  Whois({this.domain});
  Socket socket;
  String domain;
  bool dataFinished = false;
  bool doneFinished = false;
  bool getData = false;
  String s = 'start:';

  Future getWhois()async{
    await request();
    while(!dataFinished){
      await Future.delayed(Duration(milliseconds: 100));
    }
  }

  Future request()async{
    dataFinished = false;
    doneFinished = false;
    getData = false;

    try {
      socket = await Socket.connect('whois.cnnic.net.cn', 43);
      socket.listen(onData, onError: onError, onDone: onDone);
      print('============================================================================================================');
      print('$s $domain');
      socket.write(domain + '\n');
    }catch(e){
      print('from request error: ${e.toString()}');
      print('waiting 2 seconds');
      sleep(Duration(seconds: 2));
    }
  }

  void onError(e){
    print('===================== error ==============================');
    print('from error side: ${e.toString()}');
    errorFinished = true;
  }

  void onData(value)async{
    getData = true;
    String data = utf8.decode(value);
    print('===================== WHOIS ==============================');
    if(data.contains('interval')){
      print('system notice too fast, wait 2 seconds');
      socket.destroy();
      sleep(Duration(seconds: 2));
      s = 'restart';
      await request();
    }else{
      print('not find interval');
      dataFinished = true;
      print('whois:::::::: ${data.substring(0, 18)}');
    }
  }

  onDone()async{
    int t = 1;
    print('mmmmmmmmmmmmmmmmmmmmm DONE mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm');
    sleep(Duration(milliseconds: 100));
    while(t<5){

      if(getData == false){
        print('wairint data from onDone function: $t');
        sleep(Duration(milliseconds: 50));
        t++;
      }else{
        t = 5;
      }

    }
    if(getData == false){
      socket.destroy();
      print('wait too long time without response, wait 2 second to restart.');
      sleep(Duration(seconds: 2));
      s = 'restart';
      await request();
    }

  }
}

  

posted @ 2019-05-02 13:17  CrossPython  阅读(416)  评论(0编辑  收藏  举报