{"id":168,"date":"2013-05-21T11:41:44","date_gmt":"2013-05-21T17:41:44","guid":{"rendered":"https:\/\/www.guammie.com\/donovan\/?p=168"},"modified":"2013-05-21T11:41:44","modified_gmt":"2013-05-21T17:41:44","slug":"hostname-and-ip-from-ipconfig-files","status":"publish","type":"post","link":"https:\/\/www.guammie.com\/donovan\/2013\/05\/21\/hostname-and-ip-from-ipconfig-files\/","title":{"rendered":"hostname and ip from ipconfig files"},"content":{"rendered":"<p>i\u2019m currently working on a wireless deployment with a requirement to use mac filtering.&#160; There are over 600 laptops being deployed to a unique location per laptop.&#160; Part of the imaging process doesan ipconfig and dumps the output to a text file which I can then use to copy\/paste the hostname and mac into the Cisco 8510 wireless controller.&#160; I\u2019m lazy, so I made a bash script to parse the ipconfig text files. I wish I knew how to do this in Windows, but I work with what I got. The script takes this input from a text file:<\/p>\n<blockquote>\n<p>Windows IP Configuration<\/p>\n<p>&#160;&#160; Host Name . . . . . . . . . . . . : GU0123LT01     <br \/>&#160;&#160; Primary Dns Suffix&#160; . . . . . . . : guammie.com      <br \/>&#160;&#160; Node Type . . . . . . . . . . . . : Hybrid      <br \/>&#160;&#160; IP Routing Enabled. . . . . . . . : No      <br \/>&#160;&#160; WINS Proxy Enabled. . . . . . . . : No      <br \/>&#160;&#160; DNS Suffix Search List. . . . . . : guammie.com      <\/p>\n<p>Wireless LAN adapter Wireless Network Connection:<\/p>\n<p>&#160;&#160; Media State . . . . . . . . . . . : Media disconnected     <br \/>&#160;&#160; Connection-specific DNS Suffix&#160; . :       <br \/>&#160;&#160; Description . . . . . . . . . . . : Ralink RT5390R 802.11b\/g\/n 1&#215;1 Wi-Fi Adapter      <br \/>&#160;&#160; Physical Address. . . . . . . . . : B8-76-3F-25-34-4D      <br \/>&#160;&#160; DHCP Enabled. . . . . . . . . . . : Yes      <br \/>&#160;&#160; Autoconfiguration Enabled . . . . : Yes<\/p>\n<p>Ethernet adapter Local Area Connection:<\/p>\n<p>&#160;&#160; Connection-specific DNS Suffix&#160; . :      <br \/>&#160;&#160; Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller      <br \/>&#160;&#160; Physical Address. . . . . . . . . : B4-B5-2F-8D-BF-2B      <br \/>&#160;&#160; DHCP Enabled. . . . . . . . . . . : No      <br \/>&#160;&#160; Autoconfiguration Enabled . . . . : Yes      <br \/>&#160;&#160; IPv4 Address. . . . . . . . . . . : 10.1.0.10(Preferred)       <br \/>&#160;&#160; Subnet Mask . . . . . . . . . . . : 255.255.255.0      <br \/>&#160;&#160; Default Gateway . . . . . . . . . : 10.1.0.1      <br \/>&#160;&#160; DNS Servers . . . . . . . . . . . : 10.0.0.53      <br \/>&#160;&#160; NetBIOS over Tcpip. . . . . . . . : Enabled<\/p>\n<\/blockquote>\n<p>And generates this command line that I can just copy\/paste into the controller:<\/p>\n<blockquote>\n<p>config macfilter add B8:76:3F:25:34:4D 18 guunit-clients &quot;unit 0123 laptop&quot;<\/p>\n<\/blockquote>\n<p>Here\u2019s the script.&#160; It\u2019s not the cleanest, but it works:<\/p>\n<blockquote>\n<p>#!\/bin\/bash     <br \/>FILES=\/home\/donovan\/macs\/*.txt      <br \/>for f in $FILES      <br \/>do      <br \/>&#160; # take action on each file. $f store current file name      <br \/>&#160; hostname=&quot;$(awk &#8216;\/Host Name\/ {c=1}c&#8211;&gt;0&#8217; $f | sed -n &#8216;\/\\&lt;Host Name\\&gt;\/ s\/.*[[:space:]]\\([[:alnum:]]\\+\\)$\/\\1\/p&#8217; | awk &#8216;{print substr($0,3,4)}&#8217;)&quot;      <br \/>&#160; mac=&quot;$(awk &#8216;\/Ralink RT5390R\/ {c=1;next}c&#8211;&gt;0&#8217; $f | awk -F &#8216;Physical Address. . . . . . . . . : &#8216; &#8216;{print $2}&#8217; | sed &#8216;s\/\\-\/\\:\/g&#8217;)&quot;<\/p>\n<p>echo &quot;config macfilter add $mac 18 guunit-clients \\&quot;unit $hostname laptop\\&quot;&quot;<\/p>\n<p>done<\/p>\n<\/blockquote>\n<p>That\u2019s it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i\u2019m currently working on a wireless deployment with a requirement to use mac filtering.&#160; There are over 600 laptops being deployed to a unique location per laptop.&#160; Part of the imaging process doesan ipconfig and dumps the output to a text file which I can then use to copy\/paste the hostname and mac into the [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,3],"tags":[],"class_list":["post-168","post","type-post","status-publish","format-standard","hentry","category-linux","category-networking"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1tGEc-2I","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/posts\/168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/comments?post=168"}],"version-history":[{"count":0,"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/posts\/168\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/media?parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/categories?post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guammie.com\/donovan\/wp-json\/wp\/v2\/tags?post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}