Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import getpass
- import ipaddress
- import subprocess
- pingcommand = 'ping -c 1 -w 1 %s'
- sledcommand = 'ipmitool -H %s -U %s -P %s -I lanplus raw 0x30 0xe1 %d'
- def run(command):
- cmd = command.split(' ')
- output = subprocess.run(cmd, stdout=subprocess.PIPE)
- return output.stdout.decode()
- userid = input('Enter BMC userid: ')
- password = getpass.getpass('Enter BMC password: ')
- subnet = input('Enter BMC subnet: ')
- n = ipaddress.IPv4Network(subnet)
- summary = ''
- for host in [str(h) for h in n.hosts()]:
- if '0% packet loss' in run(pingcommand % host):
- print('Sending IPMI to', host, ' (15 second timeout if host does not respond)')
- try:
- sledid = 0
- bitposition = 0
- for i in [123, 124, 125]: # Magic numbers to retrieve sled position as three single bits
- bit = run(sledcommand % (host, userid, password, i)).split(' ')[2]
- sledid += int(bit) * 2**bitposition
- bitposition += 1
- summary += 'Host %s is in sled position: %d\n' % (host,sledid)
- except:
- continue
- print(summary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement