2017-08-24 76 views
0

我有IP地址的列表,我想使用Netmiko功能連接到每個IP的又將..通過列表進行遍歷每個值傳遞給函數在Python

功能具有IP作爲第一個參數,但我不確定如何遍歷列表,將每個值作爲第一個必需參數傳遞。

我有遠這樣的:

def find_mac(ip,username,password) 

    ip_list = ['1.1.1.1','2.2.2.2'] 
    for i in ip_list: 
     find_mac(list[0],username,password) 

將使用第一個列表項的每次迭代(如預期),但我將如何去每次遍歷列表時使用一個表項?

所以首先它connectes爲1.1.1.1,然後2.2.2.2等等

我敢肯定,這是直線前進,我很抱歉,如果我的術語是有點過...謝謝提前!

回答

0
def find_mac(ip, username, password): 
    # some magic 
    return something 

ip_list = ['1.1.1.1','2.2.2.2'] 
uname = "myawesomeusername" 
pwd = "hunter2" 
for ip in ip_list: 
    print(find_mac(ip, uname, pwd)) 
+0

非常感謝!我已經實現了這一點,它現在正在做我想要的東西:) – uberkind