Posts

Showing posts from July, 2023

How to create DHCP server and a policy in the Fortigate

Here is an example script that demonstrates how to use the  fortigate-api  package to create a DHCP server and a policy in the Fortigate   from fortigate_api import FortigateAPI # Create a FortigateAPI object fgt = FortigateAPI(host="host", username="username", password="password") # Create a DHCP server data = {     "default-gateway": "192.168.255.1",     "netmask": "255.255.255.0",     "interface": "vlan.123",     "ip-range": [         {"start-ip": "192.168.255.2", "end-ip": "192.168.255.254",}     ], } fgt.dhcp_server.create(data) # Create a policy in the Fortigate data = dict(     name="POLICY",     status="enable",     action="accept",     srcintf=[{"name": "any"}],     dstintf=[{"name": "any"}],     srcaddr=[{"name": "all"}],     dstaddr=[{"name&quo

PYTHON PROGRAM FOR FLSM USING CLASS C IP ADDRESS ONLY

Image
PYTHON PROGRAM FOR FLSM USING CLASS C IP ADDRESS ONLY   ip , cidr = input ( "Enter the the Network ID with CIDR value for which you need FLSM (ONLY FOR CLASS C): " ). split ( '/' ) ip1 , ip2 , ip3 , ip4 = ip . split ( '.' ) req_host = int ( input ( "Enter the no of Required Host: " )) for h in range ( 0 , 15 ):     if 2 ** h >= req_host :         sm = int ( cidr )+ 8 - h         nid = 8 - h         for i in range ( 2 ** nid ):             valid_host =( 2 ** h )* i             print ( f " { ip1 } . { ip2 } . { ip3 } . { int ( ip4 )+ valid_host } / { sm } " )         break     OUTPUT RESULT Note: I n the Above Program I have created two variables on the first line named “ IP and CIDR” These two variables are taking the input of Network ID and CIDR value of any class “C” subnet as a string and then splitting it with ‘/’ than on the next line I have created 4 variables which are dividing the IPv4 32 Bi