Jump to content

phpIPAM - API [WIP]


JRSmile
 Share

Recommended Posts

i thought i leave them here.

used curl udf and json udf.

#Include "Curl.au3"
#Include "Json.au3"
#include <Array.au3>

; Your own proxy server
Global $ProxySever = "http://127.0.0.1:8888"
Global $IPAM_LOGIN_TOKEN = phpIPAM_getToken("https://IPAMSERVER/api/test/user/","USER","PASS")
ConsoleWrite ("LOGIN TOKEN = " & $IPAM_LOGIN_TOKEN & @CRLF)
phpIPAM_searchDevice($IPAM_LOGIN_TOKEN,"13.13.1")

Func phpIPAM_getToken($url,$username,$password)
    Local $Curl = Curl_Easy_Init()
    If Not $Curl Then Return

    Local $Html = $Curl ; any number as identify
    Local $Header = $Curl + 1 ; any number as identify

    Curl_Easy_Setopt($Curl, $CURLOPT_URL, $url)
    Curl_Easy_Setopt($Curl, $CURLOPT_USERAGENT, "AutoIt/Curl")
    Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1)
    Curl_Easy_Setopt($Curl, $CURLOPT_ACCEPT_ENCODING, "gzip") ; or set "" use all built-in supported encodings
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html)
    Curl_Easy_Setopt($Curl, $CURLOPT_HEADERFUNCTION, Curl_DataWriteCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_HEADERDATA, $Header)
    Curl_Easy_Setopt($Curl, $CURLOPT_COOKIE, "tool=curl; script=autoit; fun=yes;")
    Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30)
    Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0)
    Curl_Easy_Setopt($Curl, $CURLOPT_POST,1)
    Curl_Easy_Setopt($Curl, $CURLOPT_USERNAME, $username)
    Curl_Easy_Setopt($Curl, $CURLOPT_PASSWORD, $password)
    Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, $ProxySever)

    Local $Code = Curl_Easy_Perform($Curl)
    If $Code = $CURLE_OK Then
        ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)
        ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)
        $Data2 = Json_Decode(BinaryToString(Curl_Data_Get($Html)))
        $json2 = Json_Encode($Data2, $Json_PRETTY_PRINT, "  ", "\n", "\n", ",")
        MsgBox(0, 'Html',$json2)
        Json_Dump($Json2)
        ConsoleWrite(Json_Get($Data2, '["data"]["token"]')& @CRLF)
        Return Json_Get($Data2, '["data"]["token"]')
    Else
        ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
    EndIf

    Curl_Easy_Cleanup($Curl)
    Curl_Data_Cleanup($Header)
    Curl_Data_Cleanup($Html)

    ConsoleWrite(@LF)
EndFunc

Func phpIPAM_searchDevice($IPAM_LOGIN_TOKEN,$device)
    Local $Curl = Curl_Easy_Init()
    If Not $Curl Then Return

    Local $Html = $Curl ; any number as identify
    Local $Header = $Curl + 1 ; any number as identify

    Curl_Easy_Setopt($Curl, $CURLOPT_URL, "https://IPAMSERVER/api/test/devices/search/"&$device&"/")
    Curl_Easy_Setopt($Curl, $CURLOPT_USERAGENT, "AutoIt/Curl")
    Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1)
    Curl_Easy_Setopt($Curl, $CURLOPT_ACCEPT_ENCODING, "gzip") ; or set "" use all built-in supported encodings
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html)
    Curl_Easy_Setopt($Curl, $CURLOPT_HEADERFUNCTION, Curl_DataWriteCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_HEADERDATA, $Header)
    Curl_Easy_Setopt($Curl, $CURLOPT_COOKIE, "tool=curl; script=autoit; fun=yes;")
    Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30)
    Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0)
    Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, $ProxySever)
    Local $Slist = Curl_Slist_Append(0, "User-Agent: AutoIt/Curl")
    $Slist = Curl_Slist_Append($Slist, "token: " & $IPAM_LOGIN_TOKEN)
    Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $Slist)


    Local $Code = Curl_Easy_Perform($Curl)
    If $Code = $CURLE_OK Then
        ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)
        ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)
        Local $Data2 = Json_Decode(BinaryToString(Curl_Data_Get($Html)))
        Local $json2 = Json_Encode($Data2, $Json_PRETTY_PRINT, "  ", "\n", "\n", ",")
        MsgBox(0, 'Html',$json2)
        Json_Dump($Json2)
;~      ConsoleWrite(Json_Get($Data2, '["data"]["token"]')& @CRLF)
;~      Return Json_Get($Data2, '["data"]["token"]')
    Else
        ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
    EndIf

    Curl_Easy_Cleanup($Curl)
    Curl_Data_Cleanup($Header)
    Curl_Data_Cleanup($Html)

    ConsoleWrite(@LF)
EndFunc

 

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

I just learned about IPAM ( Explained - Windows Server 2016 ) thanks to you posting, now,
how does phpIPAM does what ?, could not find an explanation in english ( video that is ).

Thanks for sharing

PS: I may have found an explanation on this video of solarwinds.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

On 23.2.2018 at 6:10 PM, argumentum said:

I just learned about IPAM ( Explained - Windows Server 2016 ) thanks to you posting, now,
how does phpIPAM does what ?, could not find an explanation in english ( video that is ).

Thanks for sharing

PS: I may have found an explanation on this video of solarwinds.

try it yourself: https://phpipam.net/demo/

it is a better excel sheet if you want to document your network infrastructure.

you can create subnets and devices and even scan them for uptime and document changes.

vlan and vrf docomentation as wenn as subnets even racks and cables are planable.

we use it to keep track which cable is connected to which device here. i am currently labling cable 40450 by hand and documenting it in the system with source destination, sort of cable, lwl or cat7, etc.

 

phpipam is relatively new, it can automatically detect new devices in a network and read port configuration from managed switches. 

in addition you could combine it with power-dns a bind / Windows-DNS Server alternative to manage hostnames and domainnames as well.

Edited by JRSmile
$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...