Nächste freie IP Adresse per API abrufen?
-
Hallo zusammen,
weiß jemand ob es möglich ist über die API ( i-doit Version 1.8 ) die nächste freie IP Adresse für ein bestimmtes Subnet abzurufen?
Viele Grüße, Christian
-
Ich habe mir inzwischen selbst eine Funktion in Python geschrieben. Hier der Code wer's gebrauchen kann:
#!/usr/bin/python # import modules import httplib, json, urllib from netaddr import * # get next unused ip address def i_get_next_ip(i_net_id, i_net_title): # define parameters i_params = ('{"version":"2.0", "id":"1", "method":"cmdb.category.read", "params":{' '"apikey":"' + i_api_key + '", "objID":' + i_net_id + ', "category":"C__CATS__NET_IP_ADDRESSES"}}') # connect to server i_http_conn.connect() # send POST request i_http_conn.request('POST', i_api_url, i_params, i_headers) # get response i_response = json.loads(i_http_conn.getresponse().read()) # close connection i_http_conn.close() # get result list i_result_list = i_response['result'] # list of used ip addresses i_used_ip_list = [] if i_result_list: for i in range(len(i_result_list)): i_used_ip = i_result_list[i]['title'] if i_used_ip and not i_used_ip in i_used_ip_list: i_used_ip_list.append(i_used_ip) # list of unused ip addresses subnet_unused_ip_list = [] for subnet_ip_obj in IPNetwork(i_net_title).iter_hosts(): subnet_ip_str = str(subnet_ip_obj) if not subnet_ip_str in i_used_ip_list: subnet_unused_ip_list.append(str(subnet_ip_str)) # first unused ip address first_unused_ip = subnet_unused_ip_list[0] # return value return first_unused_ip # main function if __name__ == '__main__': # global variables i_host = 'idoit.example.com' i_headers = {'Content-Type': 'application/json'} i_api_url = '/src/jsonrpc.php' i_api_key = 'abc123def456' # instantiate new httplib connection i_http_conn = httplib.HTTPConnection(i_host) # next unused ip address next_ip = ('42', '192.168.1.0/24') Die Funktion erwartet die objID des Layer 3 Netzes sowie dessen Bezeichnung, welche den Namen des Netzes im CIDR Format widerspiegeln muss. Viele Grüße, Christian[/i] -
Hallo Christian,
danke für das Beispiel! Eine weitere Möglichkeit in PHP ist hier beschrieben:
https://github.com/bheisig/i-doit-api-client-php#give-me-a-free-ip-address
Viele Grüße
Benjamin
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login