Created
January 15, 2026 18:54
-
-
Save ThinGuy/33495313182df37ee1a634f55456f0b4 to your computer and use it in GitHub Desktop.
Redfish API to re-IP iDRAC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import requests | |
| import json | |
| from requests.auth import HTTPBasicAuth | |
| import urllib3 | |
| # Disable SSL warnings if using self-signed certs | |
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
| # iDRAC credentials and current IP | |
| IDRAC_IP = "192.168.1.50" | |
| USERNAME = "root" | |
| PASSWORD = "calvin" | |
| # New network configuration | |
| NEW_IP = "192.168.1.100" | |
| NEW_NETMASK = "255.255.255.0" | |
| NEW_GATEWAY = "192.168.1.1" | |
| # Redfish API endpoint | |
| url = f"https://{IDRAC_IP}/redfish/v1/Managers/iDRAC.Embedded.1/EthernetInterfaces/NIC.1" | |
| # New configuration payload | |
| payload = { | |
| "IPv4StaticAddresses": [ | |
| { | |
| "Address": NEW_IP, | |
| "SubnetMask": NEW_NETMASK, | |
| "Gateway": NEW_GATEWAY | |
| } | |
| ], | |
| "DHCPv4": { | |
| "DHCPEnabled": False | |
| } | |
| } | |
| headers = { | |
| "Content-Type": "application/json" | |
| } | |
| # Make the PATCH request | |
| response = requests.patch( | |
| url, | |
| auth=HTTPBasicAuth(USERNAME, PASSWORD), | |
| data=json.dumps(payload), | |
| headers=headers, | |
| verify=False | |
| ) | |
| if response.status_code == 200: | |
| print(f"Successfully updated iDRAC IP to {NEW_IP}") | |
| print("Note: iDRAC will be accessible at the new IP shortly") | |
| else: | |
| print(f"Failed to update IP. Status code: {response.status_code}") | |
| print(f"Response: {response.text}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment