Changeset 7741e414ebca5089076d58982d1f967f627ace69
- Timestamp:
- 03/20/09 14:29:54 (3 years ago)
- Author:
- Frederic Lepied <frederic.lepied@…>
- Children:
- e5e582bfb02593a628c358d97bd630ff91da7f41
- Parents:
- 17e460a8150132a2f65061e57d00d0af6f545ed8
- git-committer:
- Frederic Lepied <frederic.lepied@…> (03/20/09 14:29:54)
- Message:
-
display IP address if present
- Location:
- pxe
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r8717fb5
|
r7741e41
|
|
| 14 | 14 | from models import * |
| 15 | 15 | |
| 16 | | IP_REGEXP = re.compile('^.*\s([0-9A-F:]+)\s.*') |
| | 16 | MAC_REGEXP = re.compile('^.*\s([0-9A-F:]+)\s.*') |
| | 17 | IP_REGEXP = re.compile('^([0-9.]+).*\s[0-9A-F:]+\s.*') |
| | 18 | |
| | 19 | def ip_to_mac(ip): |
| | 20 | for line in open('/proc/net/arp').readlines(): |
| | 21 | if line.find(ip) != -1: |
| | 22 | res = MAC_REGEXP.search(line) |
| | 23 | if res: |
| | 24 | return res.group(1) |
| | 25 | return None |
| 17 | 26 | |
| 18 | 27 | def mac_to_ip(mac): |
| | 28 | mac = mac.upper() |
| 19 | 29 | for line in open('/proc/net/arp').readlines(): |
| 20 | 30 | if line.find(mac) != -1: |
| … |
… |
|
| 22 | 32 | if res: |
| 23 | 33 | return res.group(1) |
| 24 | | return False |
| | 34 | return None |
| 25 | 35 | |
| 26 | 36 | def get_mac(request): |
| 27 | | mac = mac_to_ip(request.META['REMOTE_ADDR']) |
| | 37 | mac = ip_to_mac(request.META['REMOTE_ADDR']) |
| 28 | 38 | if not mac: |
| 29 | 39 | raise Http404 |
-
|
r25d22dd
|
r7741e41
|
|
| 31 | 31 | for mac in MacAddress.objects.filter(system=system): |
| 32 | 32 | print 'Mac:', |
| | 33 | r = '' |
| 33 | 34 | for i in range(0, 10, 2): |
| 34 | | sys.stdout.write('%s:' % mac.mac[i:i+2]) |
| 35 | | sys.stdout.write('%s\n' % mac.mac[10:12]) |
| | 35 | r = r + '%s:' % mac.mac[i:i+2] |
| | 36 | r = r + mac.mac[10:12] |
| | 37 | print '%s (%s)' % (r, mac_to_ip(r)) |
| 36 | 38 | |
| 37 | 39 | logs = Log.objects.filter(system=system).order_by('-date') |
| … |
… |
|
| 40 | 42 | |
| 41 | 43 | print 'History:' |
| 42 | | for l in logs[1:]: |
| | 44 | for l in logs[1:10]: |
| 43 | 45 | print l.date, l.boot_name.name |
| 44 | 46 | |