<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to SetComputerNameByDhcpScript</title><link>https://sourceforge.net/p/unattended/wiki/SetComputerNameByDhcpScript/</link><description>Recent changes to SetComputerNameByDhcpScript</description><atom:link href="https://sourceforge.net/p/unattended/wiki/SetComputerNameByDhcpScript/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 22 Sep 2014 00:46:31 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/unattended/wiki/SetComputerNameByDhcpScript/feed" rel="self" type="application/rss+xml"/><item><title>SetComputerNameByDhcpScript modified by Juan Jose Pablos</title><link>https://sourceforge.net/p/unattended/wiki/SetComputerNameByDhcpScript/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;a class="" href="../SetComputerNameByDhcpScript?action=diff&amp;amp;version=1"&gt;Last modified&lt;/a&gt; &lt;a class="" href="/trac/timeline?from=2009-05-05T12%3A28%3A42%2B02%3A00&amp;amp;precision=second"&gt;5 years&lt;/a&gt; ago Last modified on 05/05/09 12:28:42&lt;/p&gt;
&lt;p&gt;The following code can be placed in your site/config.pl. It sets the computer name of the build from the hostname of the computer as it is set by your DHCP server and is tested with the Linux boot disk. &lt;/p&gt;
&lt;p&gt;So for example, if I am using dhcpd under Linux as my dhcp server, and I have this in my /etc/dhcpd.conf configuration file: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mydomain&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;hardware&lt;/span&gt; &lt;span class="n"&gt;ethernet&lt;/span&gt; &lt;span class="mo"&gt;00&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;4F&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="n"&gt;fixed&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="mf"&gt;192.168.14.223&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then when I boot the machine with this MAC, my DHCP server will assign it that address and the hostname vm-build-test.mydomain.com. Whether the client doing the DHCP request takes any notice of it depends on the client, but Unattended does when booted using the Linux boot disk. The script will set the hostname of the computer to the first part of the DNS name shown above (the bit before the first period (.)). You can then query the hostname and use it to set the computername, which unattended will then use in the answer file it creates. All this happens before Windows Setup starts. &lt;/p&gt;
&lt;p&gt;Final notes: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tested with the Linux boot disk; can't use the DOS boot disk so can't test that but it would be worth you trying &lt;/li&gt;
&lt;li&gt;Tested by network booting, but should have no problems using the CD or floppy &lt;/li&gt;
&lt;li&gt;Will override anything in your site/unattend.txt &lt;/li&gt;
&lt;li&gt;Hostnames must be fully qualified DNS names &lt;/li&gt;
&lt;li&gt;If the script fails to split the name, it will fail quietly and unattended will fall back to watever is in your site/unattend.txt or you typed in when it prompted you &lt;/li&gt;
&lt;li&gt;The script gets run by unattended just before Windows Setup starts, so if you haven't put anything in your site/unattend.txt you will be prompted and then this script will run. Stick anything in site/unattend.txt to stop unattended prompting you. &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I put the two sleep lines in so I would have a chance to see what was happening - feel free to take them out. &lt;/p&gt;
&lt;p&gt;use warnings;&lt;br /&gt;
use strict;&lt;br /&gt;
use Sys::Hostname;&lt;/p&gt;
&lt;h1 id="start-by-trying-to-decide-the-computer-name-from-the-dhcp-dns-name"&gt;Start by trying to decide the computer name from the DHCP DNS name&lt;/h1&gt;
&lt;p&gt;my $host = hostname;&lt;br /&gt;
my $default_computer_name = $u-&amp;gt;{'UserData'}-&amp;gt;{'ComputerName'}; &lt;br /&gt;
print "Trying to determine the computer name...\n";&lt;br /&gt;
print "Hostname name from DHCP is \"$host\"\n";&lt;br /&gt;
$host =~ m/^((&lt;span&gt;[A-Z]&lt;/span&gt;|&lt;span&gt;[a-z]&lt;/span&gt;|&lt;span&gt;[0-9]&lt;/span&gt;|-)+)(..*)/;&lt;br /&gt;
my $short_host = $1;&lt;br /&gt;
my $dns_domain = $3;&lt;br /&gt;
if( ! defined($short_host))&lt;br /&gt;
{&lt;br /&gt;
    # if we couldn't get a value for the hostname from the DHCP assigned&lt;br /&gt;
    # value, don't worry. Just go with the unattend,txt default of value&lt;br /&gt;
    # entered at prompt&lt;br /&gt;
    print "WARNING: Couldn't set computer name from hostname. Hostname should be fully qualified domain name using only A-Z, a-z, 0-9 and -.\n\nUsing default from unattend.txt or prompt of $default_computer_name instead\n";&lt;br /&gt;
    sleep 10;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{ &lt;br /&gt;
    print "Success! Computer name will be \"$1\". \nDomain name is: $3\n";&lt;br /&gt;
    $u-&amp;gt;{'UserData'}-&amp;gt;{'ComputerName'} = $short_host;&lt;br /&gt;
    sleep 3;&lt;br /&gt;
}&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a class="alink" href="/p/unattended/wiki/IanGibbs"&gt;[IanGibbs]&lt;/a&gt; &amp;lt;flash666 at yahoo.com&amp;gt;&lt;/p&gt;
&lt;p&gt;cool &lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Juan Jose Pablos</dc:creator><pubDate>Mon, 22 Sep 2014 00:46:31 -0000</pubDate><guid>https://sourceforge.netc16c042697ac4cf9f2bd09f0d287c9dfdbd2ad73</guid></item></channel></rss>