### Automate Device Creation with Loops Source: https://github.com/kimmknight/ptbuilder/blob/main/README.md Leverage JavaScript loops to efficiently create multiple devices. This example demonstrates creating 10 switches with incremental positioning. ```javascript for (let n=1; n <= 10; n++) { addDevice("S" + n,"2960-24TT",n * 100,100); } ``` -------------------------------- ### Get Devices by Type or Name Prefix Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Retrieves device names as an array of strings. Can filter by device type or a name prefix. ```javascript getDevices("router") ``` ```javascript getDevices(0) ``` ```javascript getDevices(["switch", "router", "multilayerswitch"]) ``` ```javascript getDevices([0, 1, 16]) ``` ```javascript getDevices("switch", "HQ-") ``` -------------------------------- ### Iterate and Configure Devices Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Iterates through a list of devices obtained from getDevices and applies configuration commands using configureIosDevice. ```javascript for (var device of getDevices(["router","switch","multilayerswitch"])) { configureIosDevice(device, "enable secret class"); } ``` -------------------------------- ### `configurePcIp` — Configure IP settings on a PC or Server Source: https://context7.com/kimmknight/ptbuilder/llms.txt Sets the IP configuration on a PC or Server device's FastEthernet0 port. All parameters except `deviceName` are optional. When `dhcpEnabled` is `true`, the device will use DHCP. When a static `ipAddress` is provided a `subnetMask` should also be provided. `defaultGateway` and `dnsServer` are independently optional. ```APIDOC ## `configurePcIp` ### Description Sets the IP configuration on a PC or Server device's FastEthernet0 port. All parameters except `deviceName` are optional. When `dhcpEnabled` is `true`, the device will use DHCP. When a static `ipAddress` is provided a `subnetMask` should also be provided. `defaultGateway` and `dnsServer` are independently optional. ### Parameters - **deviceName** (string) - Required - The name of the device to configure. - **dhcpEnabled** (boolean) - Optional - Whether to enable DHCP. Defaults to `false`. - **ipAddress** (string) - Optional - The static IP address to assign. Required if `dhcpEnabled` is `false` and no DHCP is used. - **subnetMask** (string) - Optional - The subnet mask for the static IP address. Required if `ipAddress` is provided. - **defaultGateway** (string) - Optional - The default gateway address. - **dnsServer** (string) - Optional - The DNS server address. ``` -------------------------------- ### addModule Source: https://context7.com/kimmknight/ptbuilder/llms.txt Inserts a hardware expansion module into a specified device and slot. The device is temporarily powered off and then restored. Returns true on success, false on failure. ```APIDOC ## addModule ### Description Inserts a hardware expansion module into a named device at the given slot identifier. The device is powered off automatically before insertion and restored to its previous power state afterwards. The `slot` string follows Packet Tracer notation (e.g., `"0/0"`, `"2/0"`, `"0/0/1"`). Returns `true` on success, `false` on failure. ### Method addModule(deviceName, slot, moduleModel) ### Parameters #### Path Parameters - **deviceName** (string) - Required - The name of the device to add the module to. - **slot** (string) - Required - The slot identifier for the module (e.g., `"0/0"`, `"2/0"`). - **moduleModel** (string) - Required - The model of the hardware module to insert (e.g., `"HWIC-1GE-SFP"`). ### Request Example ```javascript addDevice("R1", "2911", 100, 100); addModule("R1", "0/0", "HWIC-1GE-SFP"); addModule("R1", "0/1", "HWIC-2T"); ``` ### Response #### Success Response (true) Returns `true` if the module was added successfully. #### Failure Response (false) Returns `false` if the operation failed (e.g., invalid slot or module). ``` -------------------------------- ### configurePcIp Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Configures the IP address settings on a PC or Server. Most parameters are optional. ```APIDOC ## configurePcIp ### Description Configures the IP address settings on a PC or Server. ### Parameters - **deviceName** (string) - Required - The name of the PC or Server. - **dhcpEnabled** (boolean) - Optional - Whether DHCP is enabled. - **ipAddress** (string) - Optional - The static IP address. - **subnetMask** (string) - Optional - The subnet mask for the static IP address. - **defaultGateway** (string) - Optional - The default gateway. - **dnsServer** (string) - Optional - The DNS server address. ### Notes - All parameters except _deviceName_ are optional. - If _ipAddress_ is specified, _subnetMask_ should also be specified. ### Example ```javascript configurePcIp("PC1", false, "192.168.0.10", "255.255.255.0", "192.168.0.1") ``` ``` -------------------------------- ### Add Device to Workspace Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Adds a device to the logical workspace. Ensure the device model is from the supported list. ```javascript addDevice("R1","2911",100,100) ``` -------------------------------- ### addDevice Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Adds a device to the logical workspace. The device model must be selected from a predefined list. ```APIDOC ## addDevice ### Description Adds a device to the logical workspace. ### Parameters - **deviceName** (string) - Required - The name of the device. - **deviceModel** (string) - Required - The model of the device (must be from the list of supported models). - **x** (number) - Required - The x-coordinate for the device. - **y** (number) - Required - The y-coordinate for the device. ### Example ```javascript addDevice("R1","2911",100,100) ``` ``` -------------------------------- ### configureIosDevice Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Sends configuration commands to a Cisco IOS device. ```APIDOC ## configureIosDevice ### Description Sends configuration commands to a Cisco IOS device. ### Parameters - **deviceName** (string) - Required - The name of the device to configure. - **commands** (string) - Required - A string containing the configuration commands, separated by newlines. ### Example ```javascript configureIosDevice("R2", "hostname R1\ninterface GigabitEthernet0/1\nno shutdown") ``` ``` -------------------------------- ### Create Cable Links Between Devices Source: https://context7.com/kimmknight/ptbuilder/llms.txt Use `addLink` to connect interfaces between devices using specified cable types. Interface names must match Packet Tracer exactly (e.g., "GigabitEthernet0/0"). Cable types like "straight", "cross", "serial", "console", and "fiber" are supported and case-insensitive. ```javascript // Router uplink to switch (straight-through) addLink("R1", "GigabitEthernet0/0", "S1", "GigabitEthernet0/1", "straight"); // Switch to PC (straight-through) addLink("S1", "FastEthernet0/1", "PC1", "FastEthernet0", "straight"); addLink("S1", "FastEthernet0/2", "PC2", "FastEthernet0", "straight"); // Router-to-router serial WAN link addLink("R1", "Serial0/0/0", "R2", "Serial0/0/0", "serial"); // Switch-to-switch crossover addLink("S1", "GigabitEthernet0/1", "S2", "GigabitEthernet0/1", "cross"); // Console connection from PC to router addLink("PC1", "RS 232", "R1", "Console", "console"); // Fiber uplink between switches addLink("S1", "GigabitEthernet0/2", "S2", "GigabitEthernet0/2", "fiber"); ``` -------------------------------- ### Configure PC IP Settings Source: https://context7.com/kimmknight/ptbuilder/llms.txt Sets IP configuration on a PC or Server's FastEthernet0 port. DHCP can be enabled. Static IP requires a subnet mask. Default gateway and DNS server are optional. ```javascript configurePcIp("PC1", false, "192.168.1.10", "255.255.255.0", "192.168.1.1", "8.8.8.8"); ``` ```javascript // Static IP on PC2 (no DNS) configurePcIp("PC2", false, "192.168.1.11", "255.255.255.0", "192.168.1.1"); ``` ```javascript // Enable DHCP on a laptop configurePcIp("Laptop1", true); ``` ```javascript // Static server address configurePcIp("SRV1", false, "192.168.1.100", "255.255.255.0", "192.168.1.1", "192.168.1.100"); ``` ```javascript // Build and configure a full PC subnet automatically for (let n = 1; n <= 5; n++) { addDevice("PC" + n, "PC-PT", n * 150, 300); addLink("S1", "FastEthernet0/" + n, "PC" + n, "FastEthernet0", "straight"); configurePcIp("PC" + n, false, "10.0.0." + (n + 10), "255.255.255.0", "10.0.0.1" ); } ``` -------------------------------- ### Add Hardware Modules to Devices Source: https://context7.com/kimmknight/ptbuilder/llms.txt The `addModule` function inserts expansion modules into a specified slot of a device. The device is temporarily powered off and then restored to its original power state. Ensure the slot identifier follows Packet Tracer's notation (e.g., "0/0", "2/0", "0/0/1"). ```javascript // Add a GigabitEthernet SFP module to a router addDevice("R1", "2911", 100, 100); addModule("R1", "0/0", "HWIC-1GE-SFP"); // Add a serial WAN interface card addModule("R1", "0/1", "HWIC-2T"); // Add a GLC-TE SFP transceiver to an ISR4331 addDevice("R2", "ISR4331", 300, 100); addModule("R2", "0/0/0", "GLC-TE"); // Add a Fast Ethernet switch module to a router addDevice("R3", "Router-PT-Empty", 500, 100); addModule("R3", "0/0", "PT-ROUTER-NM-1CFE"); addModule("R3", "1/0", "PT-ROUTER-NM-1CGE"); ``` -------------------------------- ### `configureIosDevice` — Send IOS commands to a Cisco router or switch Source: https://context7.com/kimmknight/ptbuilder/llms.txt Enters a multi-line configuration string into the specified IOS device. Each line of `commands` is sent as a separate CLI command in global configuration mode. The device boots are skipped automatically. Configuration is saved with `write memory` after the commands are applied. ```APIDOC ## `configureIosDevice` ### Description Sends a multi-line configuration string to a specified IOS device. Each line in the `commands` string is executed as a separate CLI command in global configuration mode. Device reboots are skipped, and the configuration is saved using `write memory` upon completion. ### Parameters - **deviceName** (string) - Required - The name of the IOS device (router or switch) to configure. - **commands** (string) - Required - A multi-line string containing the IOS commands to execute. Each command should be on a new line. ``` -------------------------------- ### Add Devices to Packet Tracer Workspace Source: https://context7.com/kimmknight/ptbuilder/llms.txt Use `addDevice` to place named devices of specific models at given canvas coordinates. Supported models include routers, switches, PCs, servers, laptops, and IoT devices. Routers, switches, and multilayer switches will have their boot process automatically skipped. ```javascript // Add a router, a switch, and two PCs laid out horizontally addDevice("R1", "2911", 100, 200); addDevice("S1", "2960-24TT", 300, 200); addDevice("PC1", "PC-PT", 500, 100); addDevice("PC2", "PC-PT", 500, 300); // Add a server and a laptop addDevice("SRV1", "Server-PT", 700, 200); addDevice("Laptop1", "Laptop-PT", 900, 200); // Add IoT things addDevice("TempSensor1", "Temperature Sensor", 100, 400); addDevice("Light1", "Light", 300, 400); ``` -------------------------------- ### Add Devices and Links in Packet Tracer Source: https://github.com/kimmknight/ptbuilder/blob/main/README.md Use these functions to add devices like routers, switches, and PCs, and to create links between them. Specify device type, name, and coordinates. ```javascript addDevice("R1","2911",100,100); addDevice("S1","2960-24TT",200,100); addDevice("PC1","PC-PT",300,100); addLink("R1","GigabitEthernet0/1","S1","GigabitEthernet0/1", "straight"); addLink("S1","FastEthernet0/1","PC1","FastEthernet0", "straight"); ``` -------------------------------- ### `getDevices` — Retrieve device names from the active network Source: https://context7.com/kimmknight/ptbuilder/llms.txt Returns an array of device name strings currently present in the logical workspace. Optionally filtered by device type and/or a name prefix via `startsWith`. When no filter is provided, all devices are returned. ```APIDOC ## `getDevices` ### Description Retrieves a list of device names from the current network topology. Devices can be filtered by type (using string category names or numeric type IDs) and/or by a name prefix. If no filters are applied, all devices in the workspace are returned. ### Parameters - **deviceTypes** (string | number | Array) - Optional - Specifies the type(s) of devices to retrieve. Can be a single type name (e.g., "router"), a single type ID (e.g., 1), or an array of type names and/or IDs. - **startsWith** (string) - Optional - A prefix string to filter device names. Only devices whose names start with this prefix will be returned. ``` -------------------------------- ### Configure IOS Device Commands Source: https://context7.com/kimmknight/ptbuilder/llms.txt Sends multi-line CLI commands to a Cisco IOS device in global configuration mode. Automatically skips reboots and saves configuration with 'write memory'. ```javascript // Basic router hostname and interface config configureIosDevice("R1", "hostname HQ-Router\n" + "interface GigabitEthernet0/0\n" + " ip address 192.168.1.1 255.255.255.0\n" + " no shutdown \n" + "interface GigabitEthernet0/1\n" + " ip address 10.0.0.1 255.255.255.0\n" + " no shutdown" ); ``` ```javascript // Configure OSPF on a router configureIosDevice("R1", "router ospf 1\n" + " network 192.168.1.0 0.0.0.255 area 0\n" + " network 10.0.0.0 0.0.0.255 area 0" ); ``` ```javascript // Harden a switch with VLANs and port security configureIosDevice("S1", "vlan 10\n" + " name SALES\n" + "vlan 20\n" + " name IT\n" + "interface range FastEthernet0/1 - 12\n" + " switchport mode access\n" + " switchport access vlan 10\n" + " switchport port-security maximum 1\n" + " switchport port-security violation restrict\n" + " switchport port-security" ); ``` ```javascript // Apply a basic ACL to a router interface configureIosDevice("R1", "ip access-list extended BLOCK_TELNET\n" + " deny tcp any any eq 23\n" + " permit ip any any\n" + "interface GigabitEthernet0/0\n" + " ip access-group BLOCK_TELNET in" ); ``` -------------------------------- ### Create Link Between Devices Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Creates a link between two devices, specifying interfaces and link type. The link type must be from the supported list. ```javascript addLink("R1","GigabitEthernet0/0","S1","GigabitEthernet0/1", "straight") ``` -------------------------------- ### addLink Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Creates a link between two devices, specifying the interfaces on each device and the type of link. ```APIDOC ## addLink ### Description Creates a link between two devices. ### Parameters - **device1Name** (string) - Required - The name of the first device. - **device1Interface** (string) - Required - The interface on the first device. - **device2Name** (string) - Required - The name of the second device. - **device2Interface** (string) - Required - The interface on the second device. - **linkType** (string) - Required - The type of link (must be from the list of supported link types). ### Example ```javascript addLink("R1","GigabitEthernet0/0","S1","GigabitEthernet0/1", "straight") ``` ``` -------------------------------- ### addDevice Source: https://context7.com/kimmknight/ptbuilder/llms.txt Adds a device of a specified model to the Packet Tracer logical workspace at given canvas coordinates. Returns true on success, false if the model is not recognized. ```APIDOC ## addDevice ### Description Places a named device of a given model at the specified (x, y) canvas coordinates. The `deviceModel` must be one of the supported model strings (e.g., `"2911"`, `"2960-24TT"`, `"PC-PT"`). Routers, switches, and multilayer switches have boot automatically skipped. Returns `true` on success, `false` if the model is not recognised. ### Method addDevice(deviceName, deviceModel, x, y) ### Parameters #### Path Parameters - **deviceName** (string) - Required - The name to assign to the device. - **deviceModel** (string) - Required - The model of the device to add (e.g., `"2911"`, `"PC-PT"`). - **x** (number) - Required - The x-coordinate for placing the device on the canvas. - **y** (number) - Required - The y-coordinate for placing the device on the canvas. ### Request Example ```javascript addDevice("R1", "2911", 100, 200); addDevice("S1", "2960-24TT", 300, 200); addDevice("PC1", "PC-PT", 500, 100); ``` ### Response #### Success Response (true) Returns `true` if the device was added successfully. #### Failure Response (false) Returns `false` if the `deviceModel` is not recognized. ``` -------------------------------- ### addModule Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Adds a module to a specified device. Modules are added to specific slots within a device. ```APIDOC ## addModule ### Description Adds a module to a device. ### Parameters - **deviceName** (string) - Required - The name of the device to add the module to. - **slot** (string) - Required - The slot identifier for the module (e.g., "0/0", "2/0", "0/0/1"). - **model** (string) - Required - The model of the module (must be from the list of supported module models). ### Examples ```javascript addModule("R1","0/0","HWIC-1GE-SFP") addModule("R1","0/0/0","GLC-TE") ``` ``` -------------------------------- ### Add Module to Device Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Adds a module to a specified device. The slot format is typically 'X/Y' or 'X/Y/Z'. ```javascript addModule("R1","0/0","HWIC-1GE-SFP") ``` ```javascript addModule("R1","0/0/0","GLC-TE") ``` -------------------------------- ### Configure PC IP Settings Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Configures IP address settings on a PC or Server. IP address and subnet mask are required if DHCP is disabled. ```javascript configurePcIp("PC1", false, "192.168.0.10", "255.255.255.0", "192.168.0.1") ``` -------------------------------- ### getDevices Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Returns the names of devices in the current network as an array of strings, with optional filtering. ```APIDOC ## getDevices ### Description Returns the names of devices in the current network as an array of strings. ### Parameters - **filter** (string | number | array) - Optional - Specifies the type(s) of device to return. Can be a string (e.g., "router"), a number (ID), or an array of strings/numbers. - **startsWith** (string) - Optional - A string that the device name must start with. ### Notes - If _filter_ is not specified, all devices will be returned. - Device types can be specified from a list of supported device types. ### Examples ```javascript getDevices("router") getDevices(0) getDevices(["switch", "router", "multilayerswitch"]) getDevices([0, 1, 16]) getDevices("switch", "HQ-") // Example usage in a loop: for (var device of getDevices(["router","switch","multilayerswitch"])) { configureIosDevice(device, "enable secret class"); } ``` ``` -------------------------------- ### addLink Source: https://context7.com/kimmknight/ptbuilder/llms.txt Creates a cable link between two specified interfaces on different devices using a given cable type. Returns true on success. ```APIDOC ## addLink ### Description Connects two device interfaces with a specified cable type. `device1Interface` and `device2Interface` must match the exact interface names shown in Packet Tracer (e.g., `"GigabitEthernet0/0"`, `"FastEthernet0/1"`, `"Serial0/0/0"`). The `linkType` is case-insensitive and can use short aliases (`"straight"` for Ethernet straight-through, `"cross"` for crossover). Returns `true` on success. ### Method addLink(device1Name, device1Interface, device2Name, device2Interface, linkType) ### Parameters #### Path Parameters - **device1Name** (string) - Required - The name of the first device. - **device1Interface** (string) - Required - The interface name on the first device. - **device2Name** (string) - Required - The name of the second device. - **device2Interface** (string) - Required - The interface name on the second device. - **linkType** (string) - Required - The type of cable to use (e.g., `"straight"`, `"cross"`, `"serial"`, `"console"`, `"fiber"`). ### Request Example ```javascript addLink("R1", "GigabitEthernet0/0", "S1", "GigabitEthernet0/1", "straight"); addLink("S1", "FastEthernet0/1", "PC1", "FastEthernet0", "straight"); addLink("R1", "Serial0/0/0", "R2", "Serial0/0/0", "serial"); ``` ### Response #### Success Response (true) Returns `true` if the link was created successfully. ``` -------------------------------- ### Retrieve Device Names Source: https://context7.com/kimmknight/ptbuilder/llms.txt Returns an array of device name strings from the active workspace. Can be filtered by device type or name prefix. Useful for iterating over devices for bulk operations. ```javascript // Get all devices in the network var all = getDevices(); console.log(all); // ["R1", "S1", "PC1", "PC2", ...] ``` ```javascript // Get all routers by type name var routers = getDevices("router"); ``` ```javascript // Get all switches and multilayer switches by type ID var switches = getDevices([1, 16]); ``` ```javascript // Get devices whose names start with "HQ-" var hqDevices = getDevices(["router", "switch", "multilayerswitch"], "HQ-"); ``` ```javascript // Apply a common banner to every router for (var r of getDevices("router")) { configureIosDevice(r, "banner motd # Authorised access only #\n" + "enable secret cisco\n" + "line vty 0 4\n" + " password cisco\n" + " login" ); } ``` ```javascript // Bulk-configure all PCs in the network with DHCP for (var pc of getDevices("pc")) { configurePcIp(pc, true); } ``` -------------------------------- ### Configure Cisco IOS Device Source: https://github.com/kimmknight/ptbuilder/wiki/Functions Sends configuration commands to a Cisco IOS device. Commands can include multiple lines separated by newlines. ```javascript configureIosDevice("R2", "hostname R1\ninterface GigabitEthernet0/1\nno shutdown") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.