Advertisement
jsf80238

juniper1.py

Jan 17th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 0 0
  1. import pprint
  2. class rule():
  3.     def __init__(self, name, match_clause, then_clause):
  4.         self.name = name
  5.         self.match_clause = match_clause
  6.         self.then_clause = then_clause
  7.     def __repr__(self):
  8.         # This next line causes the print() function to render something useful.
  9.         # Comment out the def line and the line below to see the difference
  10.         return(", ".join(["%s=%s" % (key, value) for key, value in sorted(self.__dict__.items())]))
  11.  
  12. class rule_set():
  13.     def __init__(self, name, from_zone, rule_list):
  14.         self.name = name
  15.         self.from_zone = from_zone
  16.         self.rule_list = rule_list
  17.     def __repr__(self):
  18.         return(", ".join(["%s=%s" % (key, value) for key, value in sorted(self.__dict__.items())]))
  19.  
  20. if __name__ == "__main__":
  21.     my_rule = rule("rule-1", "destination-address 194.1.1.10/32", "static-nat prefix 10.17.10.10/32")
  22.     my_rule_list = [my_rule]
  23.     my_rule_set = rule_set("static-nat-Untrust", "Untrust", my_rule_list)
  24.     print(my_rule_set)
  25.  
  26. """
  27. Juniper SRX
  28. ----------
  29. interfaces {
  30.    ge-0/0/0 {
  31.        unit 0 {
  32.            family inet {
  33.                address 194.1.1.1/24;
  34.            }
  35.        }
  36.    }
  37.    ge-2/0/5 {
  38.        unit 0 {
  39.            family inet {
  40.                address 10.17.10.1/24;
  41.            }
  42.        }
  43.    }
  44. }
  45. security {
  46.    nat {
  47.        static {
  48.            rule-set static-nat-"Untrust" {
  49.                from zone "Untrust";
  50.                rule rule-1 {
  51.                    match {
  52.                        destination-address 194.1.1.10/32;
  53.                    }
  54.                    then {
  55.                        static-nat prefix 10.17.10.10/32;
  56.                    }
  57.                }
  58.         rule rule-2 {
  59.                    match {
  60.                        destination-address 194.1.1.20/32;
  61.                    }
  62.                    then {
  63.                        static-nat prefix 10.17.10.20/32;
  64.                    }
  65.                }
  66.            }
  67.        }
  68.        proxy-arp {
  69.            interface ge-0/0/0.0 {
  70.                address {
  71.                    194.1.1.10/32;
  72.             194.1.1.20/32;
  73.                }
  74.            }
  75.        }
  76.    }
  77.    zones {
  78.        security-zone Untrust {
  79.            interfaces {
  80.                ge-0/0/0.0;
  81.            }
  82.        }
  83.        security-zone DMZ {
  84.            address-book {
  85.                address mx1.union.com  10.17.10.10/32;
  86.                address mx2.union.com  10.17.10.20/32;
  87.            }
  88.            interfaces {
  89.                ge-2/0/5.0;
  90.            }
  91.        }
  92.    }
  93.    policies {
  94.        from-zone Untrust to-zone DMZ {
  95.            /* "CR4444567" */
  96.            policy 100 {
  97.                match {
  98.                    source-address any;
  99.                    destination-address [ mx1.union.com mx2.union.com ];
  100.                    application junos-smtp;
  101.                }
  102.                then {
  103.                    permit;
  104.                    log {
  105.                        session-init;
  106.                    }
  107.                }
  108.            }
  109.        }
  110.    }
  111. }
  112. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement