<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python script for end-system VLAN Distribution for NAC in Network Architecture &amp; Design</title>
    <link>https://community.extremenetworks.com/t5/network-architecture-design/python-script-for-end-system-vlan-distribution-for-nac/m-p/14619#M2023</link>
    <description>If anyone is using this solution, I am posting a quick script to create the files needed to create the policies.  There is a Bash script in the solution doc but python may be a little more accessible. It is native on Mac OS X.  use this syntax: python &lt;SCRIPT name=""&gt; &amp;lt;number of vlans&amp;gt;.  &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
#!/usr/bin/pythonimport sys&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
#this program will take the following arguments&amp;lt;br /&amp;gt;
# -number of VLAN's to distribute&amp;lt;br /&amp;gt;
# This will create one file for each vlan&amp;lt;br /&amp;gt;
# the name will begin with the name in arg[2]&amp;lt;br /&amp;gt;
# for loop for each file name&amp;lt;br /&amp;gt;
# for loop to add each mac range line&amp;lt;br /&amp;gt;
vlancount=sys.argv[1]&amp;lt;br /&amp;gt;
macspervlan=int(round(256/int(vlancount),0))&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
#because the last digit of the MAC does not seem to be normally distributed,&amp;lt;br /&amp;gt;
#we have to use the entire 6th octet of the MAC&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
macbase1 = "00:"*5&amp;lt;br /&amp;gt;
macbase2 = macbase1+"0"&amp;lt;br /&amp;gt;
macbase3 = macbase1+"FF"&amp;lt;br /&amp;gt;
octetsix = 0&amp;lt;br /&amp;gt;
i=0 # used to count the number of lines written to each file&amp;lt;br /&amp;gt;
k=1 # used as a counter to increment file names&amp;lt;br /&amp;gt;
while octetsix &amp;lt; 256:&amp;lt;br /&amp;gt;
 # create and open a file&amp;lt;br /&amp;gt;
 policyfile = open("vlan-dist-policy-{:0&amp;gt;2d}.txt".format(k),"w")&amp;lt;br /&amp;gt;
 for i in range(i, macspervlan):&amp;lt;br /&amp;gt;
  # write a line to the file&amp;lt;br /&amp;gt;
  if octetsix&amp;lt;256:&amp;lt;br /&amp;gt;
   policyfile.write(macbase1 + "{:0&amp;gt;2X}".format(octetsix)+"/"+"00:"*5+"FF\n")&amp;lt;br /&amp;gt;
   octetsix+=1&amp;lt;br /&amp;gt;
  else:&amp;lt;br /&amp;gt;
   i=macspervlan&amp;lt;br /&amp;gt;
 else: &amp;lt;br /&amp;gt;
  i=0&amp;lt;br /&amp;gt;
  k+=1&amp;lt;br /&amp;gt;
  policyfile.close()&amp;lt;br /&amp;gt;
else:&amp;lt;br /&amp;gt;
 print "Successfully created {} MAC distribution policy files.".format(k-1)&amp;lt;br /&amp;gt;
 print macspervlan&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;&lt;/SCRIPT&gt;</description>
    <pubDate>Tue, 27 May 2014 20:04:00 GMT</pubDate>
    <dc:creator>Jon_Linton</dc:creator>
    <dc:date>2014-05-27T20:04:00Z</dc:date>
    <item>
      <title>Python script for end-system VLAN Distribution for NAC</title>
      <link>https://community.extremenetworks.com/t5/network-architecture-design/python-script-for-end-system-vlan-distribution-for-nac/m-p/14619#M2023</link>
      <description>If anyone is using this solution, I am posting a quick script to create the files needed to create the policies.  There is a Bash script in the solution doc but python may be a little more accessible. It is native on Mac OS X.  use this syntax: python &lt;SCRIPT name=""&gt; &amp;lt;number of vlans&amp;gt;.  &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
#!/usr/bin/pythonimport sys&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
#this program will take the following arguments&amp;lt;br /&amp;gt;
# -number of VLAN's to distribute&amp;lt;br /&amp;gt;
# This will create one file for each vlan&amp;lt;br /&amp;gt;
# the name will begin with the name in arg[2]&amp;lt;br /&amp;gt;
# for loop for each file name&amp;lt;br /&amp;gt;
# for loop to add each mac range line&amp;lt;br /&amp;gt;
vlancount=sys.argv[1]&amp;lt;br /&amp;gt;
macspervlan=int(round(256/int(vlancount),0))&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
#because the last digit of the MAC does not seem to be normally distributed,&amp;lt;br /&amp;gt;
#we have to use the entire 6th octet of the MAC&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
macbase1 = "00:"*5&amp;lt;br /&amp;gt;
macbase2 = macbase1+"0"&amp;lt;br /&amp;gt;
macbase3 = macbase1+"FF"&amp;lt;br /&amp;gt;
octetsix = 0&amp;lt;br /&amp;gt;
i=0 # used to count the number of lines written to each file&amp;lt;br /&amp;gt;
k=1 # used as a counter to increment file names&amp;lt;br /&amp;gt;
while octetsix &amp;lt; 256:&amp;lt;br /&amp;gt;
 # create and open a file&amp;lt;br /&amp;gt;
 policyfile = open("vlan-dist-policy-{:0&amp;gt;2d}.txt".format(k),"w")&amp;lt;br /&amp;gt;
 for i in range(i, macspervlan):&amp;lt;br /&amp;gt;
  # write a line to the file&amp;lt;br /&amp;gt;
  if octetsix&amp;lt;256:&amp;lt;br /&amp;gt;
   policyfile.write(macbase1 + "{:0&amp;gt;2X}".format(octetsix)+"/"+"00:"*5+"FF\n")&amp;lt;br /&amp;gt;
   octetsix+=1&amp;lt;br /&amp;gt;
  else:&amp;lt;br /&amp;gt;
   i=macspervlan&amp;lt;br /&amp;gt;
 else: &amp;lt;br /&amp;gt;
  i=0&amp;lt;br /&amp;gt;
  k+=1&amp;lt;br /&amp;gt;
  policyfile.close()&amp;lt;br /&amp;gt;
else:&amp;lt;br /&amp;gt;
 print "Successfully created {} MAC distribution policy files.".format(k-1)&amp;lt;br /&amp;gt;
 print macspervlan&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;&lt;/SCRIPT&gt;</description>
      <pubDate>Tue, 27 May 2014 20:04:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/network-architecture-design/python-script-for-end-system-vlan-distribution-for-nac/m-p/14619#M2023</guid>
      <dc:creator>Jon_Linton</dc:creator>
      <dc:date>2014-05-27T20:04:00Z</dc:date>
    </item>
  </channel>
</rss>

