Jump to content

help to linking array data


Recommended Posts

Hi,

 

I've got 3 arrays, each with 2 columns. This after requesting snmp from a switch.

What i need (in the end) is 1 array with 2 columns.
mac in decimal (preferably in hex seperated by ":" (i'll work on that obviously)) 2.0.0.36.208.3.178
interface: Gi2/0/2

Basically I need to link them like this:

mac > interface
interface > interface index
interface index > interface name

-array output example of the arrays mentioned above-
array1: [1]|1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178  | 98
array2: [31]|1.3.6.1.2.1.17.1.4.1.2.98  | 74
array3: [74]|1.3.6.1.2.1.31.1.1.1.1.74  | Gi2/0/2

The 98 value from the first array should be linked to the 1.3.6.1.2.1.17.1.4.1.2.98 (trimed to 98) value which returns 74 and then link to the third array.

 

The first array that i have contains mac and intarface value's, the second contains the interface  and interface index and the third contains the interface index and the interface name.

In each array, the first column contains a whole snmp OID which looks like: 1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178
Each of them can be Trimmed from the left by 23 characters.

 

I hope anyone understand what i'm talking about (lol) and can point me into the right direction cuz I don't really know how to approach this.

Thanks for thinking with me...

 

 

Edited by crackdonalds
Link to comment
Share on other sites

Are this arrays 0 or 1 based? Means: Does the first row contain a row/column count or does the array only hold data?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Something like this?

#include <Array.au3>
; All arrays are 1-based
Global $aArrayIn1[2][2] = [[1, 2], ["1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178", "98"]]
Global $aArrayIn2[33][2] = [[32, 2]]
$aArrayIn2[32][0] = "1.3.6.1.2.1.17.1.4.1.2.98"
$aArrayIn2[32][1] = 74
Global $aArrayIn3[75][2] = [[174, 2]]
$aArrayIn3[74][0] = "1.3.6.1.2.1.31.1.1.1.1.74"
$aArrayIn3[74][1] = "Gi2/0/2"
Global $aArrayOut[$aArrayIn1[0][0]][3]
For $i = 1 To $aArrayIn1[0][0]
    For $j = 1 To $aArrayIn2[0][0]
        If StringTrimLeft($aArrayIn2[$j][0], 23) = $aArrayIn1[$i][1] Then
            ConsoleWrite($aArrayIn1[$i][1] & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF)
            ExitLoop
        EndIf
    Next
Next

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Replace this line:

ConsoleWrite(StringTrimLeft($aArrayIn1[$i][0], 23) & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Great, i've implemented it and it works. Thanks!

Now what if i would want that first column to appear in Hex?

For a single decimal mac i made this earlier to test:

$input = InputBox("Decimal mac-addr to hex", "Enter decimal mac")
Local $bla[6]
$asd = StringSplit($input, ".", 2)

For $i = 0 To UBound($asd) - 1
$bla[$i] = Hex($asd[$i], 2)
Next


$string = _ArrayToString($bla, ":")

it works fine for one but how would it fit into the code you just made (to have all rows into hex)?

 

Hope i'm not asking too much now...

Link to comment
Share on other sites

This?

#include <Array.au3>
; All arrays are 1-based
Global $aArrayIn1[2][2] = [[1, 2], ["1.3.6.1.2.1.17.4.3.1.2.0.0.36.208.3.178", "98"]]
Global $aArrayIn2[33][2] = [[32, 2]]
$aArrayIn2[32][0] = "1.3.6.1.2.1.17.1.4.1.2.98"
$aArrayIn2[32][1] = 74
Global $aArrayIn3[75][2] = [[174, 2]]
$aArrayIn3[74][0] = "1.3.6.1.2.1.31.1.1.1.1.74"
$aArrayIn3[74][1] = "Gi2/0/2"
Global $aArrayOut[$aArrayIn1[0][0]][3]
For $i = 1 To $aArrayIn1[0][0]
    For $j = 1 To $aArrayIn2[0][0]
        If StringTrimLeft($aArrayIn2[$j][0], 23) = $aArrayIn1[$i][1] Then
            $aIP = StringSplit(StringTrimLeft($aArrayIn1[$i][0], 23), ".", 2)
            For $k = 0 To UBound($aIP) - 1
                $aIP[$k] = Hex($aIP[$k], 2)
            Next
            ConsoleWrite(StringTrimLeft($aArrayIn1[$i][0], 23) & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF) ; decimal
            ConsoleWrite(_ArrayToString($aIP, ":") & " | " & $aArrayIn3[$aArrayIn2[$j][1]][1] & @CRLF) ; hex
            ExitLoop
        EndIf
    Next
Next

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...