Hardcoded IP address Medium

We recommend that you do not hardcode IP addresses because they might change. A hardcoded IP address can make your code vulnerable to denial of service attacks and IP address spoofing to bypass security checks.

Detector ID
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1def hardcoded_ip_address_noncompliant():
2    sock = socket(AF_INET, SOCK_STREAM)
3    # Noncompliant: IP address is hardcoded.
4    sock.bind(('', 80))

Compliant example

1def hardcoded_ip_address_compliant(ip_add=None):
2    sock = socket(AF_INET, SOCK_STREAM)
3    # Compliant: IP address is not hardcoded.
4    sock.bind((ip_add, 5080))