Skip to main content
lfstudios10
New Member
July 13, 2022
Question

Create a stitch that pings IP addresses that have been given out

  • July 13, 2022
  • 4 replies
  • 7637 views

Can anyone write me a script that will ping IP addresses the Fortigate has handed out when it hands them out?  Is that a variable that's accessible?  Running 6.4.9

4 replies

Contributor
July 14, 2022

Hi there,

Can you explain further about your requirements? Together with the device and its IP address?

 

lfstudios10
New Member
July 14, 2022

I have an FG-101F. Each time it hands out a DHCP address I need it to ping that address. This will need to happen at regular intervals unless the address is no longer in the assigned pool. 

Contributor
July 14, 2022

Hi @lfstudios10 , 

 

Here is my understanding:

Fortigate give out DHCP to the devices
Fortigate ping the devices on regular intervals

May i know what you want to achieve for this requirements?

lfstudios10
New Member
July 14, 2022

That is correct. 

it’s complicated why but due to how I’m using my FortiAp units without a software switch, the devices aren’t making it into the aero table when they are remote. Since the local and remote DHCP pool is the same, it’s just easier to ping everything. 

pminarik
Staff
Staff
July 14, 2022

Some food for thought (definitely not a ready-made solution):

 

Log ID 26001 is LOG_ID_DHCP_ACK, which is logged by FortiOS whenever it does a DHCP ACK, confirming an IP for a DHCP client's request. The log entry contains a field "ip" with client's assigned IP.

 

You could set up an automation trigger to start a stitch based off this. Then you could perhaps use the %%log.ip%% variable to ping this ip in a CLI script action: exec ping %%log.ip%%

 

With that said, stitches are meant to be one-off events. You will not be able to run this on schedule/periodically. You could perhaps prepend the ping command with a ping-options command, setting a long period and total number of pings, to effectively turn it into a long-running ping command, but this will not be robust. (it won't reflect IP changes that happen during the ongoing ping command; it will not automatically restart after any failure; and I would not be surprised at all if the CLI script gets eventually timed out and killed)

lfstudios10
New Member
July 18, 2022

Doing some research, it does appear that this is a solution and I was going to suggest something similar.  There is a schedule option for the stitch so I'm not worried.  I am not a programmer however so I'm hoping someone can come up with a script that parses the DHCP log and does a ping based on the last log.  

 

I'd have two stitches run, one hourly for ping the entire log and another that is triggered based on a DHCP address being given out and that just pings the last address in the log.

lfstudios10
New Member
July 24, 2022

Anyone?

wasimc
New Member
July 24, 2022

From a general perspective the script will be simple:

1. get the output from the logs into a file

2. use a regular expression  match the string " LOG_ID_DHCP_ACK" in that file to identify the log that contains the newly assigned IP and use another regular expression to match the IP address handed out to the client. Store that IP into another variable.

3. ping that IP and print the output

lfstudios10
New Member
July 25, 2022

I don't even need the output in the last section.  Do you think you can provide the actual script please?