defaults.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from django.conf import settings
  2. # Search for the real IP address in the following order
  3. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
  4. # X-Forwarded-For: <client>, <proxy1>, <proxy2>
  5. # Configurable via settings.py
  6. IPWARE_META_PRECEDENCE_ORDER = getattr(settings,
  7. 'IPWARE_META_PRECEDENCE_ORDER', (
  8. 'HTTP_X_FORWARDED_FOR', 'X_FORWARDED_FOR',
  9. 'HTTP_CLIENT_IP',
  10. 'HTTP_X_REAL_IP',
  11. 'HTTP_X_FORWARDED',
  12. 'HTTP_X_CLUSTER_CLIENT_IP',
  13. 'HTTP_FORWARDED_FOR',
  14. 'HTTP_FORWARDED',
  15. 'HTTP_VIA',
  16. 'REMOTE_ADDR',
  17. )
  18. )
  19. # Private IP addresses
  20. # http://en.wikipedia.org/wiki/List_of_assigned_/8_IPv4_address_blocks
  21. # https://en.wikipedia.org/wiki/Reserved_IP_addresses
  22. # https://www.ietf.org/rfc/rfc1112.txt (IPv4 multicast)
  23. # http://www.ietf.org/rfc/rfc3330.txt (IPv4)
  24. # http://www.ietf.org/rfc/rfc5156.txt (IPv6)
  25. # https://www.ietf.org/rfc/rfc6890.txt
  26. # Regex would be ideal here, but this is keeping it simple
  27. # Configurable via settings.py
  28. IPWARE_PRIVATE_IP_PREFIX = getattr(settings,
  29. 'IPWARE_PRIVATE_IP_PREFIX', (
  30. '0.', # messages to software
  31. '10.', # class A private block
  32. '100.64.', '100.65.', '100.66.', '100.67.', '100.68.', '100.69.',
  33. '100.70.', '100.71.', '100.72.', '100.73.', '100.74.', '100.75.',
  34. '100.76.', '100.77.', '100.78.', '100.79.', '100.80.', '100.81.',
  35. '100.82.', '100.83.', '100.84.', '100.85.', '100.86.', '100.87.',
  36. '100.88.', '100.89.', '100.90.', '100.91.', '100.92.', '100.93.',
  37. '100.94.', '100.95.', '100.96.', '100.97.', '100.98.', '100.99.',
  38. '100.100.', '100.101.', '100.102.', '100.103.', '100.104.', '100.105.',
  39. '100.106.', '100.107.', '100.108.', '100.109.', '100.110.', '100.111.',
  40. '100.112.', '100.113.', '100.114.', '100.115.', '100.116.', '100.117.',
  41. '100.118.', '100.119.', '100.120.', '100.121.', '100.122.', '100.123.',
  42. '100.124.', '100.125.', '100.126.', '100.127.', # carrier-grade NAT
  43. '169.254.', # link-local block
  44. '172.16.', '172.17.', '172.18.', '172.19.',
  45. '172.20.', '172.21.', '172.22.', '172.23.',
  46. '172.24.', '172.25.', '172.26.', '172.27.',
  47. '172.28.', '172.29.', '172.30.', '172.31.', # class B private blocks
  48. '192.0.0.', # reserved for IANA special purpose address registry
  49. '192.0.2.', # reserved for documentation and example code
  50. '192.168.', # class C private block
  51. '198.18.', '198.19.', # reserved for inter-network communications between two separate subnets
  52. '198.51.100.', # reserved for documentation and example code
  53. '203.0.113.', # reserved for documentation and example code
  54. '224.', '225.', '226.', '227.', '228.', '229.', '230.', '231.', '232.',
  55. '233.', '234.', '235.', '236.', '237.', '238.', '239.', # multicast
  56. '240.', '241.', '242.', '243.', '244.', '245.', '246.', '247.', '248.',
  57. '249.', '250.', '251.', '252.', '253.', '254.', '255.', # reserved
  58. ) + (
  59. '::', # Unspecified address
  60. '::ffff:', '2001:10:', '2001:20:' # messages to software
  61. '2001::', # TEREDO
  62. '2001:2::', # benchmarking
  63. '2001:db8:', # reserved for documentation and example code
  64. 'fc00:', # IPv6 private block
  65. 'fe80:', # link-local unicast
  66. 'ff00:', # IPv6 multicast
  67. )
  68. )
  69. IPWARE_LOOPBACK_PREFIX = (
  70. '127.', # IPv4 loopback device (Host)
  71. '::1', # IPv6 loopback device (Host)
  72. )
  73. IPWARE_NON_PUBLIC_IP_PREFIX = IPWARE_PRIVATE_IP_PREFIX + IPWARE_LOOPBACK_PREFIX