ChatGPT and the Network Engineer – Part 1

tiktok, artificial intelligence, ai-6767502.jpg

Last updated on February 10th, 2023 at 08:44 am

The goal of this article is not to describe ChatGPT but provide my experience as a Network Engineer using ChatGPT. If you want to know more about it, visit these two links, Wikipedia ChatGPT, and OpenAI ChatGPT FAQ. Also, this is a multipart article, so click here for Part 2 and Part 3.

I’ve explained some of my IT background in many of my articles on this site. I started my IT career in 1993 when the dial-up modem was the connection for a PC to a very early Internet. Many sites were also bulletin board systems, similar to Reddit, but very rough, and some were CLI based. At the time, this was a source of information, but there was not as much as we have today.

As an IT Support or Network Engineer in the 90s and early 2000s, we worked with Novell Netware and Windows for Workgroups or Windows NT Server as some examples. At the time, we had official product manuals or third-party books, but I found that third-party books were better than manuals. Today, the manuals are online, including third-party books, blogs, and videos. Social media platforms are also a source of help.

Here is a picture of the case I carried around in my car when I was an IT consultant in the 90s and early 2000s. It was filled with the manuals, third-party books I mentioned, OS CDs, and floppies. For this picture, I used more modern books. The old Novell NetWare and other books are long gone.

Enter ChatGPT

I’ve seen a lot of hype about ChatGPT and recently decided to check it out. So, for the past couple of weeks, I’ve been testing it in many ways, especially from the perspective of a Network Engineer. I will also publish an article from the perspective of leadership. Also, I created a second version of this article so as not to make this one too long, Part 2.

In this article, I will review the following using ChatGPT:

One thing I noticed is it’s not perfect. It will correct itself, especially when you call it out on a mistake, though I expect this to improve over time. Also, how the initial or follow-up question or request is phrased does affect the response/output.

In Part 2 of this article series, I cover Palo Alto Networks CLI commands, BGP configurations, and using Python and Excel files to resolve IP addresses. With Part 3, I review using ChatGPT for creating network documentation.

Also, any configurations/codes should be reviewed and tested. Often, what is provided is a start, baseline, or template, but it is also based on the question(s) or information provided to ChatGPT.

Let’s Get Into ChatGPT

ARPANET

I wanted to start simple, so I asked a simple question. Not much to comment about.

Asking what is ARPANET

IP Subnet

Network Engineers or Administrators and others use IP subnetting. There are many IP calculators and cheat sheets on this subject, though I thought I’d test ChatGPT. It passed with flying colors.

IP Subnet

Cisco Interface Best Practices

Now to start putting ChatGPT to the test!

I ask for the best practices for a Cisco access port in this example. The output is straightforward, and it’s nice that explanations are included. Then, the best part is I ask for a configuration, and it provides a configuration example with a “Copy code” snippet.

I won’t go into the details of the response/code, but it looks good. Keep in mind this is not a one size fits all. With configurations, code, or scripts, know what each command does. Research if that command(s) is needed, and if so, what variables and the impact.

Cisco Interface Best Practice
Cisco Interface Best Practice Part 2

Wireshark

Wireshark is an essential tool for Network Engineers and many others in IT. It has two filters for packet capture, Capture, and Display. The capture filter will filter the actual packets captured, and the display filter will filter out what was captured. Sometimes these filters can be long and complex. Wireshark has improved over versions with interactive responses when creating a filter.

I tested ChatGPT asking to create capture and display filters. Though what I used is not as complex as it could be, they worked well. The filters ChatGPT provided were tested on production traffic.

Here is the capture filter request.

Wireshark Capture Filter

Applying the capture filter in Wireshark.

Capture filter applied

The display filter request.

Display filter request

The display filter in Wireshark.

Display filter applied

NMAP

If you’re not familiar with NMAP, then you need to be. Used by many IT Security, iNetwork Engineers also use it to scan networks and hosts. There’s a GUI and CLI version, and both are available for some operating systems. NMAP is available for Windows, Linux, Unix, and MAC versions.

The CLI is most commonly used with NMAP, and the Windows GUI version supports CLI commands. I asked ChatGPT to create a couple of NMAP scan commands, and both tested in the Windows GUI version, and both worked as expected. I’m impressed with the explanation of the options used in the command.

The NMAP command here is basic, a scan of the 192.168.100.0/24 network for all open TCP ports.

TCP Scan of Subnet for TCP

This time, for the 100 most popular ports.

Scan of a Subnet for 100 most popular

Python Script

Well, this is one area in ChatGPT that has excellent potential. Python is very popular in networks and with Network Engineers and Administrators. Many years ago, I took an introductory Python course but did not have time to complete it. I knew what I wanted to do with it but did not learn Python programming. If you’re interested in a good Python programming book for Network Engineers, I recommend Mastering Python Networking.

So I put ChatGPT to the task of creating a Python script. The goal is to place a specific interface in a specified VLAN using SSH. As you view the conversation chain, I had to update it with a request to show the output. I then informed the interface commands were not executing. Then we have a working Python script.

Initial Python request
Update requesting to show command output
Updated output showing script output
Updating chat the script is not working
Updated and working script
Description of the working update

Here is the working script as provided by ChatGPT.

import paramiko
import time

# Create an SSH client
client = paramiko.SSHClient()

# Automatically add a missing host key
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Connect to the switch
client.connect(hostname='192.168.1.1', username='admin', password='password')

# Create an SSH channel
channel = client.invoke_shell()

# Configure the interface
channel.send('configure terminal\n')
channel.send('interface g1/0/10\n')
channel.send('switchport access vlan 202\n')

# wait for the commands to execute
time.sleep(1)

channel.send('exit\n')

# Read the output
output = channel.recv(4096).decode()
print(output)

# Close the channel
channel.close()

# Close the SSH client
client.close()

I modified this script, adding the Cisco interface best practices shown in the Cisco Interface Best Practices section.

import paramiko
import time

# Create an SSH client
client = paramiko.SSHClient()

# Automatically add the server's host key (useful for the first time connecting)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Connect to the switch
client.connect(hostname='192.168.1.1', username='admin', password='password')

# Open a channel to the switch
channel = client.invoke_shell()

# Send commands to configure the interface
channel.send('configure terminal\n')
channel.send('interface g1/0/27\n')
channel.send('switchport mode access\n')
channel.send('switchport access vlan 10\n')
channel.send('switchport port-security\n')
channel.send('switchport port-security maximum 2\n')
channel.send('storm-control broadcast level pps 1000\n')
channel.send('storm-control multicast level pps 1000\n')
channel.send('storm-control action trap\n')
channel.send('exit\n')

# wait for the commands to execute
time.sleep(1)

channel.send('exit\n')

# Read the output
output = channel.recv(4096).decode()
print(output)

# Close the channel
channel.close()

# Close the SSH client
client.close()

I tested this script on my test Cisco switch. The first image is before executing the script, and the second after. So the script works as expected.

Pre-python script
Post python script

Conclusion

ChatGPT is a resource that can provide the starting point for Network Engineers and, of course, many others. I believe ChatGPT is here and here to stay and will improve over time. Am I excited about ChatGPT? Most certainly. At least I don’t have to carry a case full of books anymore!

Want to know when I add new or update content? Sign up for email updates.

Copyright © Packet Passers 2024