<commit_before>#!/usr/bin/python

import commands
import json

class theIP:
    iface=""
    ipaddr=""
    netmask=""
    brdcast=""
    gateway=""
    dns=""
    macaddr=""
    
    def __init__(self, interfaceid):
        self.iface=interfaceid
        cmd = "ifconfig %s | grep 'inet addr:' |cut -d: -f2 | awk '{ print $1}'" % interfaceid
        self.ipaddr = commands.getoutput(cmd)
        if "error" in self.ipaddr: 
            self.ipaddr = ""
            return
        cmd = "ifconfig %s | grep 'inet addr:' |cut -d: -f3 | awk '{ print $1}'" % interfaceid
        self.brdcast = commands.getoutput(cmd)
        
        cmd = "ifconfig %s | grep 'inet addr:' |cut -d: -f4 | awk '{ print $1}'" % interfaceid
        self.netmask = commands.getoutput(cmd)
        
        cmd = r"route -n | grep 'UG[ \t]' | awk '{print $2}'"
        self.gateway = commands.getoutput(cmd)
    
    def __str__(self):
        d = {}
        d["interface"]=self.iface
        d["ipaddr"]=self.ipaddr
        d["netmask"]=self.netmask
        d["brdcast"]=self.brdcast
        return json.dumps(d)
        

def main():
    i = theIP("eth0")
    print i.ipaddr
    print i.netmask
    print i.brdcast
    print i.dns
    print i.gateway
    print i.macaddr
    print i


if __name__ == "__main__":
    main()<commit_msg>add interface function<commit_after>#!/usr/bin/python

import commands
import json
import netifaces

class theIP:
    iface=""
    ipaddr=""
    netmask=""
    brdcast=""
    gateway=""
    dns=""
    macaddr=""
    
    def __init__(self, interfaceid):
        self.iface=interfaceid
        cmd = "ifconfig %s | grep 'inet addr:' |cut -d: -f2 | awk '{ print $1}'" % interfaceid
        self.ipaddr = commands.getoutput(cmd)
        if "error" in self.ipaddr: 
            self.ipaddr = ""
            return
        cmd = "ifconfig %s | grep 'inet addr:' |cut -d: -f3 | awk '{ print $1}'" % interfaceid
        self.brdcast = commands.getoutput(cmd)
        
        cmd = "ifconfig %s | grep 'inet addr:' |cut -d: -f4 | awk '{ print $1}'" % interfaceid
        self.netmask = commands.getoutput(cmd)
        
        cmd = r"route -n | grep 'UG[ \t]' | awk '{print $2}'"
        self.gateway = commands.getoutput(cmd)
    
    def __str__(self):
        d = {}
        d["interface"]=self.iface
        d["ipaddr"]=self.ipaddr
        d["netmask"]=self.netmask
        d["brdcast"]=self.brdcast
        return json.dumps(d)
        
def getipaddr(iface):
    if not iface:
        return ""
    try:
        ips = netifaces.ifaddresses(iface)[netifaces.AF_INET]
        ret = [];
        for i in ips:
            ret.append(i["addr"])
    except ValueError as e:
        print "bad value"

    return ret

def getifaces():
    return netifaces.interfaces()

def getipaddres():
    ret = {}
    for i in netifaces.interfaces():
        ret[i] = getipaddr(i)

    return ret


def main():
    i = theIP("eth0")
    print i.ipaddr
    print i.netmask
    print i.brdcast
    print i.dns
    print i.gateway
    print i.macaddr
    print i


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.13980582524271845, 'fraction_numerical': 0.005177993527508091, 'mean_word_length': 2.0038872691933918, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2092074', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1057, 'n_words': 264}