whois_handler.dart
import 'dart:io';
import 'package:async/async.dart';
import 'dart:convert'; class Whois{
Whois({this.domain}); Socket socket;
String domain; bool dataFinished = false;
bool doneFinished = false;
bool errorFinished = false;
bool saveFinished = false;
bool getData = false; int tryTimes = 0;
int tryDone = 0;
int errorTime = 0; String rawWhois = ''; Future request()async{
dataFinished = false;
doneFinished = false;
errorFinished = false;
saveFinished = false;
getData = false; try {
socket = await Socket.connect('whois.cnnic.net.cn', 43);
socket.listen(onData, onError: onError);
socket.write(domain + '\n');
}catch(e){
print('0, create socket error: ${e.toString()}');
} try{
await socket.done;
print('4. $domain done');
}catch(error){
print('1, transit error: ${error.toString()}');
await Future.delayed(Duration(seconds: 2));
await request();
}
} void onData(value)async {
getData = true;
rawWhois = utf8.decode(value);
print('3. whois: $rawWhois}');
saveFinished = true;
print('mmmmmmmmmmmmmmmmmmmmmmm $domain done mmmmmmmmmmmmmmmmmmmmmmmm');
} void onError(e)async{
socket.destroy();
print('error: ${e.toString()}'); if(errorTime<2){
await Future.delayed(Duration(seconds: 2));
request();
errorTime++;
}else{
print('5. try too many times but failed, force to next');
saveFinished = true;
}
} }
main.dart
import 'package:flutter/material.dart';
import 'package:spatialhash/spatialhash.dart';
import 'utils/whois_handler.dart';
import 'dart:async'; main()=>runApp(MaterialApp(
home: MyApp(),
)); class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyAppState();
}
} class MyAppState extends State<MyApp> {
List a = ['1000.cn','1001.cn','1002.cn','1003.cn','1004.cn','1005.cn','1006.cn','1007.cn','1008.cn','1009.cn','1010.cn','1011.cn','1012.cn','1013.cn','1014.cn','1015.cn','1016.cn','1017.cn','1018.cn','1019.cn','1020.cn','1021.cn','1022.cn','1023.cn','1024.cn','1025.cn','1026.cn','1027.cn','1028.cn','1029.cn','1030.cn','1031.cn','1032.cn','1033.cn','1034.cn','1035.cn','1036.cn','1037.cn','1038.cn','1039.cn','1040.cn','1041.cn','1042.cn','1043.cn','1044.cn','1045.cn','1046.cn','1047.cn','1048.cn','1049.cn','1050.cn','1051.cn','1052.cn','1053.cn','1054.cn','1055.cn','1056.cn','1057.cn','1058.cn','1059.cn','1060.cn','1061.cn','1062.cn','1063.cn','1064.cn','1065.cn','1066.cn','1067.cn','1068.cn','1069.cn','1070.cn','1071.cn','1072.cn','1073.cn','1074.cn','1075.cn','1076.cn','1077.cn','1078.cn','1079.cn','1080.cn','1081.cn','1082.cn','1083.cn','1084.cn','1085.cn','1086.cn','1087.cn','1088.cn','1089.cn','1090.cn','1091.cn','1092.cn','1093.cn','1094.cn','1095.cn','1096.cn','1097.cn','1098.cn','1099.cn','1100.cn','1101.cn','1102.cn','1103.cn','1104.cn','1105.cn','1106.cn','1107.cn','1108.cn','1109.cn','1110.cn','1111.cn','1112.cn','1113.cn','1114.cn','1115.cn','1116.cn','1117.cn','1118.cn','1119.cn','1120.cn','1121.cn','1122.cn','1123.cn','1124.cn','1125.cn','1126.cn','1127.cn','1128.cn','1129.cn','1130.cn','1131.cn','1132.cn','1133.cn','1134.cn','1135.cn','1136.cn','1137.cn','1138.cn','1139.cn','1140.cn','1141.cn','1142.cn','1143.cn','1144.cn','1145.cn','1146.cn','1147.cn','1148.cn','1149.cn','1150.cn','1151.cn','1152.cn','1153.cn','1154.cn','1155.cn','1156.cn','1157.cn','1158.cn','1159.cn','1160.cn','1161.cn','1162.cn','1163.cn','1164.cn','1165.cn','1166.cn','1167.cn','1168.cn','1169.cn','1170.cn','1171.cn','1172.cn','1173.cn','1174.cn','1175.cn','1176.cn','1177.cn','1178.cn','1179.cn','1180.cn','1181.cn','1182.cn','1183.cn','1184.cn','1185.cn','1186.cn','1187.cn','1188.cn','1189.cn','1190.cn','1191.cn','1192.cn','1193.cn','1194.cn','1195.cn','1196.cn','1197.cn','1198.cn','1199.cn','1200.cn','1201.cn','1202.cn','1203.cn','1204.cn','1205.cn','1206.cn','1207.cn','1208.cn','1209.cn','1210.cn','1211.cn','1212.cn','1213.cn','1214.cn','1215.cn','1216.cn','1217.cn','1218.cn','1219.cn','1220.cn','1221.cn','1222.cn','1223.cn','1224.cn','1225.cn','1226.cn','1227.cn','1228.cn','1229.cn','1230.cn','1231.cn','1232.cn','1233.cn','1234.cn','1235.cn','1236.cn','1237.cn','1238.cn','1239.cn','1240.cn','1241.cn','1242.cn','1243.cn','1244.cn','1245.cn','1246.cn','1247.cn','1248.cn','1249.cn','1250.cn','1251.cn','1252.cn','1253.cn','1254.cn','1255.cn','1256.cn','1257.cn','1258.cn','1259.cn','1260.cn','1261.cn','1262.cn','1263.cn','1264.cn','1265.cn','1266.cn','1267.cn','1268.cn','1269.cn','1270.cn','1271.cn','1272.cn','1273.cn','1274.cn','1275.cn','1276.cn','1277.cn','1278.cn','1279.cn','1280.cn','1281.cn','1282.cn','1283.cn','1284.cn','1285.cn','1286.cn','1287.cn','1288.cn','1289.cn','1290.cn','1291.cn','1292.cn','1293.cn','1294.cn','1295.cn','1296.cn','1297.cn','1298.cn','1299.cn','1300.cn','1301.cn','1302.cn','1303.cn','1304.cn','1305.cn','1306.cn','1307.cn','1308.cn','1309.cn','1310.cn','1311.cn','1312.cn','1313.cn','1314.cn','1315.cn','1316.cn','1317.cn','1318.cn','1319.cn','1320.cn','1321.cn','1322.cn','1323.cn','1324.cn','1325.cn','1326.cn','1327.cn','1328.cn','1329.cn','1330.cn','1331.cn','1332.cn','1333.cn','1334.cn','1335.cn','1336.cn','1337.cn','1338.cn','1339.cn','1340.cn','1341.cn','1342.cn','1343.cn','1344.cn','1345.cn','1346.cn','1347.cn','1348.cn','1349.cn','1350.cn','1351.cn','1352.cn','1353.cn','1354.cn','1355.cn','1356.cn','1357.cn','1358.cn','1359.cn','1360.cn','1361.cn','1362.cn','1363.cn','1364.cn','1365.cn','1366.cn','1367.cn','1368.cn','1369.cn','1370.cn','1371.cn','1372.cn','1373.cn','1374.cn','1375.cn','1376.cn','1377.cn','1378.cn','1379.cn','1380.cn','1381.cn','1382.cn','1383.cn','1384.cn','1385.cn','1386.cn','1387.cn','1388.cn','1389.cn','1390.cn','1391.cn','1392.cn','1393.cn','1394.cn','1395.cn','1396.cn','1397.cn','1398.cn','1399.cn','1400.cn','1401.cn','1402.cn','1403.cn','1404.cn','1405.cn','1406.cn','1407.cn','1408.cn','1409.cn','1410.cn','1411.cn','1412.cn','1413.cn','1414.cn','1415.cn','1416.cn','1417.cn','1418.cn','1419.cn','1420.cn','1421.cn','1422.cn','1423.cn','1424.cn','1425.cn','1426.cn','1427.cn','1428.cn','1429.cn','1430.cn','1431.cn','1432.cn','1433.cn','1434.cn','1435.cn','1436.cn','1437.cn','1438.cn','1439.cn','1440.cn','1441.cn','1442.cn','1443.cn','1444.cn','1445.cn','1446.cn','1447.cn','1448.cn','1449.cn','1450.cn','1451.cn','1452.cn','1453.cn','1454.cn','1455.cn','1456.cn','1457.cn','1458.cn','1459.cn','1460.cn','1461.cn','1462.cn','1463.cn','1464.cn','1465.cn','1466.cn','1467.cn','1468.cn','1469.cn','1470.cn','1471.cn','1472.cn','1473.cn','1474.cn','1475.cn','1476.cn','1477.cn','1478.cn','1479.cn','1480.cn','1481.cn','1482.cn','1483.cn','1484.cn','1485.cn','1486.cn','1487.cn','1488.cn','1489.cn','1490.cn','1491.cn','1492.cn','1493.cn','1494.cn','1495.cn','1496.cn','1497.cn','1498.cn','1499.cn','1500.cn','1501.cn','1502.cn','1503.cn','1504.cn','1505.cn','1506.cn','1507.cn','1508.cn','1509.cn','1510.cn','1511.cn','1512.cn','1513.cn','1514.cn','1515.cn','1516.cn','1517.cn','1518.cn','1519.cn','1520.cn','1521.cn','1522.cn','1523.cn','1524.cn','1525.cn','1526.cn','1527.cn','1528.cn','1529.cn','1530.cn','1531.cn','1532.cn','1533.cn','1534.cn','1535.cn','1536.cn','1537.cn','1538.cn','1539.cn','1540.cn','1541.cn','1542.cn','1543.cn','1544.cn','1545.cn','1546.cn','1547.cn','1548.cn','1549.cn','1550.cn','1551.cn','1552.cn','1553.cn','1554.cn','1555.cn','1556.cn','1557.cn','1558.cn','1559.cn','1560.cn','1561.cn','1562.cn','1563.cn','1564.cn','1565.cn','1566.cn','1567.cn','1568.cn','1569.cn','1570.cn','1571.cn','1572.cn','1573.cn','1574.cn','1575.cn','1576.cn','1577.cn','1578.cn','1579.cn','1580.cn','1581.cn','1582.cn','1583.cn','1584.cn','1585.cn','1586.cn','1587.cn','1588.cn','1589.cn','1590.cn','1591.cn','1592.cn','1593.cn','1594.cn','1595.cn','1596.cn','1597.cn','1598.cn','1599.cn','1600.cn','1601.cn','1602.cn','1603.cn','1604.cn','1605.cn','1606.cn','1607.cn','1608.cn','1609.cn','1610.cn','1611.cn','1612.cn','1613.cn','1614.cn','1615.cn','1616.cn','1617.cn','1618.cn','1619.cn','1620.cn','1621.cn','1622.cn','1623.cn','1624.cn','1625.cn','1626.cn','1627.cn','1628.cn','1629.cn','1630.cn','1631.cn','1632.cn','1633.cn','1634.cn','1635.cn','1636.cn','1637.cn','1638.cn','1639.cn','1640.cn','1641.cn','1642.cn','1643.cn','1644.cn','1645.cn','1646.cn','1647.cn','1648.cn','1649.cn','1650.cn','1651.cn','1652.cn','1653.cn','1654.cn','1655.cn','1656.cn','1657.cn','1658.cn','1659.cn','1660.cn','1661.cn','1662.cn','1663.cn','1664.cn','1665.cn','1666.cn','1667.cn','1668.cn','1669.cn','1670.cn','1671.cn','1672.cn','1673.cn','1674.cn','1675.cn','1676.cn','1677.cn','1678.cn','1679.cn','1680.cn','1681.cn','1682.cn','1683.cn','1684.cn','1685.cn','1686.cn','1687.cn','1688.cn','1689.cn','1690.cn','1691.cn','1692.cn','1693.cn','1694.cn','1695.cn','1696.cn','1697.cn','1698.cn','1699.cn','1700.cn','1701.cn','1702.cn','1703.cn','1704.cn','1705.cn','1706.cn','1707.cn','1708.cn','1709.cn','1710.cn','1711.cn','1712.cn','1713.cn','1714.cn','1715.cn','1716.cn','1717.cn','1718.cn','1719.cn','1720.cn','1721.cn','1722.cn','1723.cn','1724.cn','1725.cn','1726.cn','1727.cn','1728.cn','1729.cn','1730.cn','1731.cn','1732.cn','1733.cn','1734.cn','1735.cn','1736.cn','1737.cn','1738.cn','1739.cn','1740.cn','1741.cn','1742.cn','1743.cn','1744.cn','1745.cn','1746.cn','1747.cn','1748.cn','1749.cn','1750.cn','1751.cn','1752.cn','1753.cn','1754.cn','1755.cn','1756.cn','1757.cn','1758.cn','1759.cn','1760.cn','1761.cn','1762.cn','1763.cn','1764.cn','1765.cn','1766.cn','1767.cn','1768.cn','1769.cn','1770.cn','1771.cn','1772.cn','1773.cn','1774.cn','1775.cn','1776.cn','1777.cn','1778.cn','1779.cn','1780.cn','1781.cn','1782.cn','1783.cn','1784.cn','1785.cn','1786.cn','1787.cn','1788.cn','1789.cn','1790.cn','1791.cn','1792.cn','1793.cn','1794.cn','1795.cn','1796.cn','1797.cn','1798.cn','1799.cn','1800.cn','1801.cn','1802.cn','1803.cn','1804.cn','1805.cn','1806.cn','1807.cn','1808.cn','1809.cn','1810.cn','1811.cn','1812.cn','1813.cn','1814.cn','1815.cn','1816.cn','1817.cn','1818.cn','1819.cn','1820.cn','1821.cn','1822.cn','1823.cn','1824.cn','1825.cn','1826.cn','1827.cn','1828.cn','1829.cn','1830.cn','1831.cn','1832.cn','1833.cn','1834.cn','1835.cn','1836.cn','1837.cn','1838.cn','1839.cn','1840.cn','1841.cn','1842.cn','1843.cn','1844.cn','1845.cn','1846.cn','1847.cn','1848.cn','1849.cn','1850.cn','1851.cn','1852.cn','1853.cn','1854.cn','1855.cn','1856.cn','1857.cn','1858.cn','1859.cn','1860.cn','1861.cn','1862.cn','1863.cn','1864.cn','1865.cn','1866.cn','1867.cn','1868.cn','1869.cn','1870.cn','1871.cn','1872.cn','1873.cn','1874.cn','1875.cn','1876.cn','1877.cn','1878.cn','1879.cn','1880.cn','1881.cn','1882.cn','1883.cn','1884.cn','1885.cn','1886.cn','1887.cn','1888.cn','1889.cn','1890.cn','1891.cn','1892.cn','1893.cn','1894.cn','1895.cn','1896.cn','1897.cn','1898.cn','1899.cn','1900.cn','1901.cn','1902.cn','1903.cn','1904.cn','1905.cn','1906.cn','1907.cn','1908.cn','1909.cn','1910.cn','1911.cn','1912.cn','1913.cn','1914.cn','1915.cn','1916.cn','1917.cn','1918.cn','1919.cn','1920.cn','1921.cn','1922.cn','1923.cn','1924.cn','1925.cn','1926.cn','1927.cn','1928.cn','1929.cn','1930.cn','1931.cn','1932.cn','1933.cn','1934.cn','1935.cn','1936.cn','1937.cn','1938.cn','1939.cn','1940.cn','1941.cn','1942.cn','1943.cn','1944.cn','1945.cn','1946.cn','1947.cn','1948.cn','1949.cn','1950.cn','1951.cn','1952.cn','1953.cn','1954.cn','1955.cn','1956.cn','1957.cn','1958.cn','1959.cn','1960.cn','1961.cn','1962.cn','1963.cn','1964.cn','1965.cn','1966.cn','1967.cn','1968.cn','1969.cn','1970.cn','1971.cn','1972.cn','1973.cn','1974.cn','1975.cn','1976.cn','1977.cn','1978.cn','1979.cn','1980.cn','1981.cn','1982.cn','1983.cn','1984.cn','1985.cn','1986.cn','1987.cn','1988.cn','1989.cn','1990.cn','1991.cn','1992.cn','1993.cn','1994.cn','1995.cn','1996.cn','1997.cn','1998.cn','1999.cn','2000.cn','2001.cn','2002.cn','2003.cn','2004.cn','2005.cn','2006.cn','2007.cn','2008.cn','2009.cn','2010.cn','2011.cn','2012.cn','2013.cn','2014.cn','2015.cn','2016.cn','2017.cn','2018.cn','2019.cn','2020.cn','2021.cn','2022.cn','2023.cn','2024.cn','2025.cn','2026.cn','2027.cn','2028.cn','2029.cn','2030.cn','2031.cn','2032.cn','2033.cn','2034.cn','2035.cn','2036.cn','2037.cn','2038.cn','2039.cn','2040.cn','2041.cn','2042.cn','2043.cn','2044.cn','2045.cn','2046.cn','2047.cn','2048.cn','2049.cn','2050.cn','2051.cn','2052.cn','2053.cn','2054.cn','2055.cn','2056.cn','2057.cn','2058.cn','2059.cn','2060.cn','2061.cn','2062.cn','2063.cn','2064.cn','2065.cn','2066.cn','2067.cn','2068.cn','2069.cn','2070.cn','2071.cn','2072.cn','2073.cn','2074.cn','2075.cn','2076.cn','2077.cn','2078.cn','2079.cn','2080.cn','2081.cn','2082.cn','2083.cn','2084.cn','2085.cn','2086.cn','2087.cn','2088.cn','2089.cn','2090.cn','2091.cn','2092.cn','2093.cn','2094.cn','2095.cn','2096.cn','2097.cn','2098.cn','2099.cn','2100.cn','2101.cn','2102.cn','2103.cn','2104.cn','2105.cn','2106.cn','2107.cn','2108.cn','2109.cn','2110.cn','2111.cn','2112.cn','2113.cn','2114.cn','2115.cn','2116.cn','2117.cn','2118.cn','2119.cn','2120.cn','2121.cn','2122.cn','2123.cn','2124.cn','2125.cn','2126.cn','2127.cn','2128.cn','2129.cn','2130.cn','2131.cn','2132.cn','2133.cn','2134.cn','2135.cn','2136.cn','2137.cn','2138.cn','2139.cn','2140.cn','2141.cn','2142.cn','2143.cn','2144.cn','2145.cn','2146.cn','2147.cn','2148.cn','2149.cn','2150.cn','2151.cn','2152.cn','2153.cn','2154.cn','2155.cn','2156.cn','2157.cn','2158.cn','2159.cn','2160.cn','2161.cn','2162.cn','2163.cn','2164.cn','2165.cn','2166.cn','2167.cn','2168.cn','2169.cn','2170.cn','2171.cn','2172.cn','2173.cn','2174.cn','2175.cn','2176.cn','2177.cn','2178.cn','2179.cn','2180.cn','2181.cn','2182.cn','2183.cn','2184.cn','2185.cn','2186.cn','2187.cn','2188.cn','2189.cn','2190.cn','2191.cn','2192.cn','2193.cn','2194.cn','2195.cn','2196.cn','2197.cn','2198.cn','2199.cn','2200.cn','2201.cn','2202.cn']; checkWhois()async{
for(int i=0; i<a.length; i++){
var x = Whois(domain: a[i]);
x.request();
while(!x.saveFinished){
await Future.delayed(Duration(milliseconds: 100));
}
}
} @override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('ab'),),
body: Container(
width: double.infinity, height: double.infinity,
child: Column(
children: <Widget>[
RaisedButton(child: Text('check'),onPressed: (){
checkWhois();
},),
RaisedButton(child: Text('stop'),onPressed: (){},),
],
),
),
);
}
}