Skip to content

Commit

Permalink
Fix python code style
Browse files Browse the repository at this point in the history
  • Loading branch information
perryzjc committed Nov 17, 2023
1 parent 0ff1ac4 commit 244e3a8
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions detect_secrets/plugins/ip_public.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re

from .base import RegexBasedDetector


class IPPublicDetector(RegexBasedDetector):
"""Scans for public ip address (ipv4)
Expand All @@ -10,30 +12,37 @@ class IPPublicDetector(RegexBasedDetector):
- 172.(16-31)
- 192.168.
Reference:
Reference:
https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xhtml
https://en.wikipedia.org/wiki/Private_network
"""
secret_type = 'Public IP (ipv4)'

denylist_ipv4_address = r"""
(?<![0-9]) # Negative lookbehind: Asserts that what immediately precedes the current position in the string is not a digit
(?! # Negative lookahead: Asserts that what immediately follows the current position in the string does not match the enclosed pattern
192\.168\.| # Match "192.168."
127\.| # Match "127."
10\.| # Match "10."
172\.(?:1[6-9]|2[0-9]|3[01]) # Match "172." followed by a number between 16 and 31
# Negative lookbehind: Checks if preceding character is not a digit
(?<![0-9])
# Negative lookahead: Checks if following pattern doesn't match
(?!
# Matches "192.168.", "127.", "10.", or "172." with specific ranges
192\.168\.|
127\.|
10\.|
172\.(?:1[6-9]|2[0-9]|3[01])
)
(?: # Non-capturing group: Groups the enclosed pattern but does not create a backreference
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. # Match a number between 0 and 255 followed by a dot
){3} # Repeat the preceding non-capturing group three times
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) # Match a number between 0 and 255
(?::\d{1,5})? # Optional non-capturing group: Match a colon followed by a number between 0 and 99999 (a port number)
(?! # Negative lookahead: Asserts that what immediately follows the current position in the string does not match the enclosed pattern
[0-9] # Match a digit
# Non-capturing group for numbers 0-255 followed by a dot
(?:
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
){3}
# Matches final number in an IP address (0-255)
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
# Optional group for port number (0-99999)
(?::\d{1,5})?
# Negative lookahead: Ensures next character isn't a digit
(?!
[0-9]
)
"""

denylist = [
re.compile(denylist_ipv4_address, flags=re.IGNORECASE | re.VERBOSE)
re.compile(denylist_ipv4_address, flags=re.IGNORECASE | re.VERBOSE),
]

0 comments on commit 244e3a8

Please sign in to comment.