qqwry.d.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /// <reference types="node" />
  2. import stream from 'stream';
  3. declare namespace Spec {
  4. interface IpInfo {
  5. int: number;
  6. ip: string;
  7. Country: string;
  8. Area: string;
  9. }
  10. interface IpScopeInfo {
  11. begInt: number;
  12. endInt: number;
  13. begIP: string;
  14. endIP: string;
  15. Country: string;
  16. Area: string;
  17. }
  18. interface options {
  19. /**
  20. * 输出数据的格式 支持 'json','csv' 默认 'text'
  21. */
  22. format?: string;
  23. /**
  24. * 是否输出字段名 默认 'false'
  25. */
  26. outHeader?: Boolean;
  27. }
  28. class Driver {
  29. /**
  30. * 极速模式
  31. */
  32. speed(): void;
  33. /**
  34. * 关闭极速模式
  35. */
  36. unSpeed(): void;
  37. /**
  38. * 单IP查询
  39. * @param {number|string} ip IP地址
  40. */
  41. searchIP(ip: string | number): Spec.IpInfo;
  42. /**
  43. * IP段查询
  44. * @param {number|string} bginIP 起始IP
  45. * @param {number|string} endIP 结束IP
  46. * @param {function} [callback] 回调函数,没有回调函数择执行同步查询
  47. */
  48. searchIPScope(
  49. bginIP: string | number,
  50. endIP: string | number,
  51. callback?: Function
  52. ): Spec.IpScopeInfo[];
  53. /**
  54. * IP段查询 流
  55. * @param {number|string} bginIP 起始IP
  56. * @param {number|string} endIP 结束IP
  57. * @param {object} [options] 输出配制
  58. * @param {string} [options.fromat] 输出数据的格式 支持 'json','csv' 默认 'text'
  59. * @param {Boolean} [options.outHeader] 是否输出字段名 默认 'false'
  60. */
  61. searchIPScopeStream(
  62. bginIP: string | number,
  63. endIP: string | number,
  64. options?: options
  65. ): stream.Readable;
  66. }
  67. }
  68. declare const Qqwry: {
  69. /**
  70. * 初始化引擎
  71. */
  72. (): Spec.Driver;
  73. /**
  74. * 初始化引擎
  75. */
  76. new (): Spec.Driver;
  77. /**
  78. * 初始化引擎
  79. */
  80. init(): Spec.Driver;
  81. /**
  82. *
  83. * @param speed 开启极速模式
  84. * @param dataPath 自定义IP库路径
  85. */
  86. (speed: Boolean, dataPath?: string): Spec.Driver;
  87. /**
  88. *
  89. * @param speed 开启极速模式
  90. * @param dataPath 自定义IP库路径
  91. */
  92. new (speed: Boolean, dataPath?: string): Spec.Driver;
  93. /**
  94. *
  95. * @param speed 开启极速模式
  96. * @param dataPath 自定义IP库路径
  97. */
  98. init(speed: Boolean, dataPath?: string): Spec.Driver;
  99. /**
  100. *
  101. * @param dataPath 自定义IP库路径
  102. * @param speed 开启极速模式
  103. */
  104. (dataPath: string, speed?: Boolean): Spec.Driver;
  105. /**
  106. *
  107. * @param dataPath 自定义IP库路径
  108. * @param speed 开启极速模式
  109. */
  110. new (dataPath: string, speed?: Boolean): Spec.Driver;
  111. /**
  112. *
  113. * @param dataPath 自定义IP库路径
  114. * @param speed 开启极速模式
  115. */
  116. init(dataPath: string, speed?: Boolean): Spec.Driver;
  117. /**
  118. * ip地址转数值
  119. * @param ip ip地址
  120. */
  121. ipToInt(ip: string | number): number;
  122. /**
  123. * 数值转IP地址
  124. * @param int ip数值
  125. */
  126. intToIP(int: number): string;
  127. /**
  128. * 32位 Big Endian 与 Little Endian 数值互转
  129. * 适用于一些特殊场景 IP数值读取错误时使用
  130. * @param int 32位数值
  131. */
  132. ipEndianChange(int: number): number;
  133. };
  134. export = Qqwry;