Show
Ignore:
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:
2 modified

Legend:

Unmodified
Added
Removed
  • pxe/common.py

    r8717fb5 r7741e41  
    1414from models import * 
    1515 
    16 IP_REGEXP = re.compile('^.*\s([0-9A-F:]+)\s.*') 
     16MAC_REGEXP = re.compile('^.*\s([0-9A-F:]+)\s.*') 
     17IP_REGEXP = re.compile('^([0-9.]+).*\s[0-9A-F:]+\s.*') 
     18 
     19def 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 
    1726 
    1827def mac_to_ip(mac): 
     28    mac = mac.upper() 
    1929    for line in open('/proc/net/arp').readlines(): 
    2030        if line.find(mac) != -1: 
     
    2232            if res: 
    2333                return res.group(1) 
    24     return False 
     34    return None 
    2535 
    2636def get_mac(request): 
    27     mac = mac_to_ip(request.META['REMOTE_ADDR']) 
     37    mac = ip_to_mac(request.META['REMOTE_ADDR']) 
    2838    if not mac: 
    2939        raise Http404 
  • pxe/dpysystem

    r25d22dd r7741e41  
    3131    for mac in MacAddress.objects.filter(system=system): 
    3232        print 'Mac:', 
     33        r = '' 
    3334        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)) 
    3638     
    3739    logs = Log.objects.filter(system=system).order_by('-date') 
     
    4042     
    4143    print 'History:' 
    42     for l in logs[1:]: 
     44    for l in logs[1:10]: 
    4345        print l.date, l.boot_name.name 
    4446