Skip to content

About

Read-only inventory of FortiGate networks via REST API: interfaces, IPsec VPNs (selectors ∩ routes ∩ policies), conflicts between firewalls, free IPv4 space and next free subnet. PowerShell GUI, exports to Excel.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

fortiNetScope

Every network on your FortiGates in one window: interfaces, IPsec VPNs and the routes behind them, overlaps between firewalls, and the free IPv4 space to pick the next subnet from.

Read-only: it only sends GET requests to the FortiOS REST API with a read-only token.

PowerShell 5.1 Windows License: MIT Languages

English · Italiano


What it does

Tab Content
OVERVIEW Per firewall: model, FortiOS, API errors, networks by type, VPNs (up / down), public IPs, hosts, cleanup items, expiring licenses, conflicts, pool usage, free /24, changes since the previous load
CHANGES What changed since the previous load: networks, VPNs (peer, effective networks), public IPs; added / removed / changed
NETWORKS Every network and where it lives: interfaces (secondary IPs, VLANs, tunnels), routes, VPN selectors / routes / policies / effective networks, VIPs, IP pools, reservations
VPN One row per phase1: peer, status (up / partially up / down, phase2 up, traffic in/out MB; dialup: clients connected), effective networks, method, phase2 selectors, routes on the tunnel, policy IDs, local selectors, notes, IKE version, phase1 and phase2 parameters (proposal, DH, PFS, key life; never the PSK). Search the VPN name and use Export current tab for a customer sheet
PUBLIC_IP Every address of the WAN networks: interface IP, gateway, VIPs (with NAT and the policies that use them), IP pools, free. Public VIP / IP pool addresses outside the WANs are listed as routed
SUBNET_USAGE Each internal interface network: usable addresses, hosts seen, % used (amber ≥75%, red ≥90%), DHCP range and size, active leases, reservations
HOSTS Every IP seen by the firewalls: ARP table, DHCP leases and reservations, with MAC, hostname, interface, network, lease expiry
CONFLICTS Overlaps between different firewalls, with the destination of each side
OBJECT_CONFLICTS Objects to clean up and make uniform: same address (subnet, range, FQDN, country) with different names, groups with the same members, identical VIPs, and the same address name with a different value on different firewalls. For each name: its references (policies src/dst, groups, VIP groups, routes, phase2) and a suggestion (keep the one with most references, replace the others)
CLEANUP Disabled policies, policies never hit or not used for UnusedDays, address objects / groups / VIPs not referenced, static routes towards tunnels that are down
HEALTH FortiOS version (with a PSIRT reminder), HA members, licenses with expiry (amber within ExpiryWarnDays, red expired)
FREE_SPACE Free blocks of each pool, aggregated
RESERVED Networks you reserved
ADDRESS_MAP Tree 10/8, 172.16/12, 192.168/16 → /16 → /24, coloured free / partly used / full; for a block, the networks that occupy it and its free blocks
FIND_NETWORK Exported with Export current tab (or Export in the planner): plan with notes, networks found, reservations. Hosts needed (+ growth margin) → size of the network; first free subnets of that size, inside a pool or a CIDR, avoiding home-router ranges; Reserve. Subnet planner: open a network and Divide / Join it like a visual subnet calculator, with netmask, usable range, hosts and whether each subnet is free or used (and by what); a note per subnet (double-click), plans saved in plans.json and reopened with the same network; Reserve subnets with a note

Every column header has a ▾ filter (Excel-style: search, select all, blanks), e.g. to show one firewall only; it adds up with the search box. The search box filters the current tab. Type an IP or a CIDR (e.g. 10.20.5.7) to see the rows whose network contains it; on the VPN tab it shows the VPNs that reach it. Double-click a row for all its fields.

Effective networks of a VPN

Many VPNs declare wide selectors (e.g. 10.0.0.0/8) but route only a few hosts into the tunnel. For each phase1:

effective = phase2 selectors ∩ routes on the tunnel (static, BGP, OSPF) ∩ destinations of the accept policies towards the tunnel

  • a policy whose dstintf is the tunnel counts with all its destinations; a policy whose dstintf is a zone counts for a tunnel of the zone only with the destinations that overlap that tunnel's routes (or its selectors when it has no routes)

  • no route on the tunnel → the selectors are used, with a note

  • only 0.0.0.0/0 selectors → the routes are used

  • a policy with all, FQDN, dstaddr-negate or internet-service does not restrict

  • routes on the tunnel outside the selectors are reported in the notes

Only effective networks occupy address space and are checked for conflicts.

WAN and VIPs

  • A WAN is an interface with a public IP and role wan, or with a static default route (0.0.0.0/0) on it.
  • VIPs and IP pools inside an internal interface network of the same firewall are not listed (obvious and internal). Those on the WANs, or elsewhere, are.
  • On PUBLIC_IP, the gateway is any next hop of static routes, the routing table or SD-WAN members inside the WAN network; addresses found in the ARP table are shown as Seen in ARP (other routers / devices on the WAN).
  • A VIP is used when an accept policy has it (or its VIP group) as destination; OVERVIEW counts the VIPs used by no policy.

Roles

Role Meaning Occupies space Conflict check
Authoritative The network lives here: interfaces, effective VPN networks, routes to internal routers, VIP extip, IP pools yes yes
Declared VPN selectors, routes on the tunnel, policy destinations no no
Reference VIP mapped IPs yes no
Transit Route whose gateway is an interface IP of another configured firewall no no
Excluded Blackhole routes no no
Reserved Reserved networks yes yes (Info when the network appears in the config)

Quick start

  1. On every FortiGate create a read-only API user (no impact on traffic, sessions or HA):
config system accprofile
    edit "ro-netinventory"
        set sysgrp read
        set netgrp read
        set fwgrp read
        set vpngrp read
    next
end
config system api-user
    edit "netinventory"
        set accprofile "ro-netinventory"
        set vdom "root"
        config trusthost
            edit 1
                set ipv4-trusthost <PC_IP> 255.255.255.255
            next
        end
    next
end
execute api-user generate-key netinventory

Rollback: delete "netinventory" under config system api-user, then delete "ro-netinventory" under config system accprofile.

  1. Download the repository, then start Start-fortiNetScope.cmd (or powershell.exe -STA -File .\fortiNetScope.ps1).
  2. Firewalls and settings: add the firewalls, paste the tokens, save.
  3. Test each firewall, then Load data.

Optional, for .xlsx export: Install-Module ImportExcel -Scope CurrentUser (without it CSV files are written).

Scheduled report

.\fortiNetScope.ps1 -Auto

Writes fortiNetScope_<yyyy-MM-dd_HHmm>.xlsx and fortiNetScope_LATEST.xlsx in OutputFolder, and a log in logs\. Exit code 1 on errors. Run it with the Windows account that saved the tokens.

config.json

Created next to the script at the first start (config.sample.json is an example). Not in the repository.

Setting Default Meaning
Language system en or it
Firewalls Name, Host, Port, Vdoms, TokenEnc (DPAPI: readable only by the same Windows user on the same PC), SkipCertCheck
Pools RFC1918 Ranges analysed for free space
Discouraged home routers, Docker CIDR # note: skipped by Find network
OutputFolder Documents\fortiNetScope Reports and logs
ReservedFile reserved.json Reserved networks (relative to the script folder, or a full path such as a share)
RetentionDays 90 -Auto deletes older reports and logs (0 = keep)
UnusedDays 90 CLEANUP: policies not used for more than these days
ExpiryWarnDays 60 HEALTH: licenses expiring within these days are amber
HistoryKeep 50 Snapshots kept in OutputFolder\history for CHANGES
CheckUpdatesAtStartup true At startup the GUI asks GitHub for the latest release in the background and speaks only if a newer one exists. Help > Check for updates always answers. Not used by -Auto

API endpoints (GET only)

monitor/system/status, cmdb/system/interface, cmdb/system/zone, cmdb/vpn.ipsec/phase1-interface, cmdb/vpn.ipsec/phase2-interface, cmdb/firewall/address, cmdb/firewall/addrgrp, cmdb/router/static, cmdb/firewall/policy, cmdb/firewall/vip, cmdb/firewall/vipgrp, cmdb/firewall/ippool, monitor/router/ipv4.

Optional (an error is only a warning in the log): cmdb/system.dhcp/server, monitor/system/dhcp, monitor/network/arp, monitor/vpn/ipsec, monitor/firewall/policy, monitor/license/status, monitor/system/ha-peer.

API responses are never written to disk (phase1 contains the encrypted PSK). For CHANGES, each load saves a small snapshot of the derived inventory (networks, VPN peers and effective networks, public IP usage) in OutputFolder\history.

Troubleshooting

Symptom Cause
401 Wrong / expired token, or the PC is not in the api-user trusthost
403 The accprofile lacks a read permission
404 Endpoint not available on that FortiOS version, or wrong VDOM
Token cannot be decrypted config.json saved by another Windows user or PC: enter the token again

Known limits

  • IPv4 only
  • FQDN, geography and dynamic addresses cannot be turned into networks
  • Interfaces in DHCP / PPPoE have no IP in the configuration
  • "Free" means not present on the configured firewalls and not reserved
  • VIP usage looks at firewall policies only: with central NAT or NGFW policy-based mode a VIP can be used without appearing there
  • WAN networks larger than /22 are not expanded address by address
  • HOSTS / SUBNET_USAGE see only what the firewall knows: its ARP cache (recent traffic) and its own DHCP servers
  • Policy hit counts start from the last reboot or counter reset; "not referenced" objects may still be used by features fortiNetScope does not read (proxy policies, SD-WAN rules, central NAT...)

License

MIT

About

Read-only inventory of FortiGate networks via REST API: interfaces, IPsec VPNs (selectors ∩ routes ∩ policies), conflicts between firewalls, free IPv4 space and next free subnet. PowerShell GUI, exports to Excel.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages