agents.nim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # SPDX-License-Identifier: AGPL-3.0-only
  2. import random, strformat, strutils, sequtils
  3. randomize()
  4. const rvs = [
  5. "11.0", "40.0", "42.0", "43.0", "47.0", "50.0", "52.0", "53.0", "54.0",
  6. "61.0", "66.0", "67.0", "69.0", "70.0"
  7. ]
  8. proc rv(): string =
  9. if rand(10) < 1: ""
  10. else: "; rv:" & sample(rvs)
  11. # OS
  12. const enc = ["; U", "; N", "; I", ""]
  13. proc linux(): string =
  14. const
  15. window = ["X11", "Wayland", "Unknown"]
  16. arch = ["i686", "x86_64", "arm"]
  17. distro = ["", "; Ubuntu/14.10", "; Ubuntu/16.10", "; Ubuntu/19.10",
  18. "; Ubuntu", "; Fedora"]
  19. sample(window) & sample(enc) & "; Linux " & sample(arch) & sample(distro)
  20. proc windows(): string =
  21. const
  22. nt = ["5.1", "5.2", "6.0", "6.1", "6.2", "6.3", "6.4", "9.0", "10.0"]
  23. arch = ["; WOW64", "; Win64; x64", "; ARM", ""]
  24. trident = ["", "; Trident/5.0", "; Trident/6.0", "; Trident/7.0"]
  25. "Windows " & sample(nt) & sample(enc) & sample(arch) & sample(trident)
  26. const macs = toSeq(6..15).mapIt($it) & @["14_4", "10_1", "9_3"]
  27. proc mac(): string =
  28. "Macintosh; Intel Mac OS X 10_" & sample(macs) & sample(enc)
  29. # Browser
  30. proc presto(): string =
  31. const p = ["2.12.388", "2.12.407", "22.9.168", "2.9.201", "2.8.131", "2.7.62",
  32. "2.6.30", "2.5.24"]
  33. const v = ["10.0", "11.0", "11.1", "11.5", "11.6", "12.00", "12.14", "12.16"]
  34. &"Presto/{sample(p)} Version/{sample(v)}"
  35. # Samples
  36. proc product(): string =
  37. const opera = ["Opera/9.80", "Opera/12.0"]
  38. if rand(20) < 1: "Mozilla/5.0"
  39. else: sample(opera)
  40. proc os(): string =
  41. let r = rand(10)
  42. let os =
  43. if r < 6: windows()
  44. elif r < 9: linux()
  45. else: mac()
  46. &"({os}{rv()})"
  47. proc browser(prod: string): string =
  48. if "Opera" in prod: presto()
  49. else: "like Gecko"
  50. # Agent
  51. proc getAgent*(): string =
  52. let prod = product()
  53. &"{prod} {os()} {browser(prod)}"