Posts

Showing posts from June, 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

PROGRAM TO FIND WILDCARD MASK USING SUBNET MASK AND VICE VERA

Image
  oct1 , oct2 , oct3 , oct4 = input ( "Enter the 'Subnet Mask' to know its 'Wildcard Mask' and Vice Versa: \n " ). split ( "." ) print ( f " { 255 - int ( oct1 ) } . { 255 - int ( oct2 ) } . { 255 - int ( oct3 ) } . { 255 - int ( oct4 ) } " )   OUTPUT   Note : In the above Program I have created 4 variables naming as oct1...4 and with the help of the input function take the user input basically It depends on what input has been given by the user whether it is a “ subnet-mask” or “ wildcard-mask ” after I have used split function with “.” Which will split the user input by dot(.) and then store the data on the respective variables. In the next line, I printed the user data by using the print function where I have used ‘f’(string) to print the variable inside the string but there is one logic that has been implemented while printing you can see that “255-int(variable_name)” it is basically subtracting the variable value from

IPv4 to IPv6 Convertor

Image
  import ipaddress   def convertusingipaddress ( ipv4address ):     print ( ipaddress . IPv6Address ( '2002::' + ipv4address ). compressed )   ipaddr = input ( "Enter your ip here: " ) convertusingipaddress ( ipaddr )   OUTPUT ======================================================================================================================================================= Note : In the above-given Python program there is one inbuild library imported to convert the Ipv4 into Ipv6 i.e.; “ ipaddress ” After that in the second line one function has been defined named “ convertusingipaddress ” inside that function. I have printed using the module define at the top with the help of “.” Basically, it means the object of that inbuild module i.e.; “ IPv6Address('2002::' + ipv4address) ” will be converted in IPv6, and with “.compressed” I have compressed the original Ipv6 onto the compressed form of the IP address.

PYTHON SCRIPT FOR LAYMAN NETWOK ENGINEER

Image
  netmiko import ConnectHandler user = input ( "Enter the Username: " ) passwd = input ( "Enter the pass: " ) cisco_switch = {     'device_type' : 'cisco_ios' ,     'host' :   input ( "Enter the IP address: " ),     'username' : user ,     'password' : passwd ,     'port' : 22 ,           # optional, defaults to 22     'secret' : 'secret' ,     # optional, defaults to '' } net_connect = ConnectHandler (** cisco_switch ) print ( "What do you want to see in switch: \n 1--VLAN \n 2--INETRFACE_IP \n 3--RUNING_CONFIG \n 4--STARTUP_CONFIG \n 5--TRUNK_PORTS \n 6--SPANING_TREE \n 7--MAC_ADDRESS_TABLE \n 8--ETHERCHANNEL/PORT-CHANNEL \n 9--IP_ROUTE_DATABASE \n " ) while True :     op = int ( input ( "Enter your answer: " ))     if op == 1 :         output = net_connect . send_command ( 'sh vlan br' )         print