I have a problem in that I consult to several customers, all of which have DHCP. This suites me fine as all I have to do is set up DHCP on my laptop and I can connect to the customer network as soon as I boot up. I have a rule not to run any login scripts on any customer sites which makes it difficult for me to have customer pertinent settings set at logon. (I.e. proxy, mail servers etc...)

So each time I go to another customer I have to setup my proxy settings or start certain services...(Well this is where it all started..) So I came up with the idea of running a script (which I compiled) at startup.. I may put in a delay in case I have to wait for the address to be issued.. I also got an address reserved for me on the DHCP server.. not too difficult to arrange.

#! /usr/bin/perl use strict; use warnings; use Win32::Service; use Win32::Registry; my (%ipconf); #Change IP to DHCP Addresses and Proxy-xx:Port to Proxy Address #[n/y] Start services or not. %ipconf = ( "196.10.xx.xx" => ["Proxy-ONE:8080", "n"], "172.21.xx.xx" => ["PROXY-TWO:80", "y"]); #Check the current IP Address $::HKEY_LOCAL_MACHINE->Open("SYSTEM\\CurrentControlSet\\Services\\{199 +1FDD6-910A-44EA-B6A4-FDA4E1165BC7}\\Parameters\\Tcpip", my $ip) or di +e "Can't read IP: $^E"; $ip->QueryValueEx("DhcpIPAddress", my $type, my $value) or die "No IP +Address available: $^E"; print "Your IP Address is: $value\n"; #If Address is Work if (exists($ipconf{$value})) { if (&SetProxy($ipconf{$value}->[0])) { print " - Successful\n"; } else { print " - Failed!\n"; print "$^E\n"; } } else { print "IP $value not found!\n"; } if ($ipconf{$value}->[1] eq "y") { if (&StartSvc()) { print " - Successful\n"; } else { print " - Failed!\n"; print "$^E\n"; } } $ip->Close; ###################################################################### +################## ## ## SUB ROUTINES ## ###################################################################### +################## #Set Proxy value in Win32 Registry sub SetProxy { my $proxy = $_[0]; my $rc = 1; my $type = REG_SZ; my ($reserved, $proxy_str); print "Setting Proxy for $value to $proxy"; if ($::HKEY_CURRENT_USER->Open("Software\\Microsoft\\Windows\\Curr +entVersion\\Internet Settings", $proxy_str)) { unless ($proxy_str->SetValueEx("ProxyServer", $reserved, $type +, $proxy)) { $rc = 0; } } else { $rc = 0; } $proxy_str->Close; return($rc); } #Start Services. sub StartSvc { my $rc = 1; my (%list); my @svc_list = ("MSSQLSERVER"); foreach my $svc (@svc_list) { print "Starting $svc"; if (Win32::Service::GetServices($ENV{COMPUTERNAME}, \%list)) { unless (Win32::Service::StartService($ENV{COMPUTERNAME}, $ +list{"$svc"})) { $rc = 0; } } else { $rc = 0; } } return ($rc); }

Anyway the above code is a starting point for checking your local ip address and changing the registry to the corresponding proxy address.

Update: Code Changed to add the starting of services based on what you need to run on different networks.

-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to Set IE Proxy for different DHCP networks by AcidHawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.