IP Subnet Bits to Hex
Overview
Convert IP address and subnet mask notation
In this example, IP and subnet mask 7.7.7.0/24
is converted to IP 7.7.7.0
and mask FF.FF.FF.00
.
Supporting Concepts
Basic concepts needed for the use case
Topic | Description |
---|---|
API | An API in API AutoFlow is simply an OpenAPI model |
Server | A server accepts and handles the request and response. |
Simulation | Data simulation is a mock data simulated for the purpose of visualizing the data in every step of the workflow.
|
Scope | A scope is a namespace for variables. |
Data Types | Data types describe the different types or kinds of data that you are gonna store and work with. |
Use case specific concepts
Topic | Description |
---|---|
Action string/split-by | Returns an array that divides a string into substrings at each Unicode whitespace occurrence with leading and trailing whitespace ignored. |
Action object/get | Iterate over array of data mapping result to each array position. |
Detail
The HTTP request has an input:
{
"address" : "8.8.0.0/16"
}
The goal of the operation is to convert the subnet mask bits to hex:
{
"address": "8.8.0.0",
"mask": "FF.FF.00.00"
}
Content
INPUT: HTTP Request
1: Create an API endpoint
Learn how to create an API.
Create an API
From the left navigation, go to the API section and create a new API.
- ID:
sample-data-transformation
Create an API Path
- Path:
/ip-subnet-bits-to-hex
- Method: POST
2. Create a Server Operation
Learn how to create a Server.
Create a Server
From the left navigation, go to the Server section and create a new Server.
- Server ID:
sample-data-transformation
- Port Number:
1114
Feel free to select your own port number - Linked API:
sample-data-transformation
(select the API you created above)
Create a Server Operation
- Press the "Add API Operation"
- Select the API endpoint created above
3 : Create Data Simulation using Real Data
Learn how to create a Simulation.
We will use the "real data" to create the test simulation.
1. Send a HTTP request from Postman or CURL
API Autoflow Postman Collections
cURL
curl --location 'localhost:1114/ip-subnet-bits-to-hex' \
--header 'Content-Type: application/json' \
--data '{
"address" : "8.8.0.0/16"
}'
2. Check the data is received by the server endpoint
API Autoflow captures the data received and it can be used to create data simulation.
Action(s)
Learn how to create a Actions.
Add actions to transform the data.
1. Split the IP and Mask in character /
The original data "8.8.0.0/16"
needs to be split at /
to create an array of IP and subnet mask ["8.8.0.0","16"]
.
2. Create subnet mask bits to hex object
You can cut and paste the Bits to Hex object from the end of this document to the action's object.
Variable Set Action
3. Get the Hex value from object
From the hex object, get the hex value that corresponds to the subnet mask bit value stored in variables: output > 1
.
Object Get
OUTPUT: HTTP Response
1. Create a NEW object and map the IP and Subnet
Since we need to respond in a JSON object, we can create a new object in the HTTP response.
- IP Address: Getting it from the variables:
output > 0
that was created in the step 1 string split action - mask: Getting it from the variables:
output > 1
that was modified in the step 3 object get action
HTTP Response
SETTINGS
body: object
address: data variables:
output > 0
mask: data variables:output > 1
- Data referenced in HTTP response is what gets sent back to the client.
- Map the output from the actions to be sent back.
NOTE: By default, the action output is set to variable output. If you intend to keep each action's output without it being overwritten by the next action, simply rename the output location in the action's output.
2. Test the API with Postman or CURL
cURLcurl --location 'localhost:1114/ip-subnet-bits-to-hex' \
--header 'Content-Type: application/json' \
--data '{
"address" : "8.8.0.0/16"
}'
Bits to Hex table
{
"1": "80.00.00.00",
"2": "C0.00.00.00",
"3": "E0.00.00.00",
"4": "F0.00.00.00",
"5": "F8.00.00.00",
"6": "FC.00.00.00",
"7": "FE.00.00.00",
"8": "FF.00.00.00",
"9": "FF.80.00.00",
"10": "FF.C0.00.00",
"11": "FF.E0.00.00",
"12": "FF.F0.00.00",
"13": "FF.F8.00.00",
"14": "FF.FC.00.00",
"15": "FF.FE.00.00",
"16": "FF.FF.00.00",
"17": "FF.FF.80.00",
"18": "FF.FF.C0.00",
"19": "FF.FF.E0.00",
"20": "FF.FF.F0.00",
"21": "FF.FF.F8.00",
"22": "FF.FF.FC.00",
"23": "FF.FF.FE.00",
"24": "FF.FF.FF.00",
"25": "FF.FF.FF.80",
"26": "FF.FF.FF.C0",
"27": "FF.FF.FF.E0",
"28": "FF.FF.FF.F0",
"29": "FF.FF.FF.F8",
"30": "FF.FF.FF.FC",
"31": "FF.FF.FF.FE",
"32": "FF.FF.FF.FF"
}