You could just use netsh.
> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Paul Sobey > Sent: Monday, February 28, 2005 7:18 PM > To: Perl-Win32-Admin > Cc: Perl-Win32-Users > Subject: RE: Change network interface parameters via Perl > > > Assuming you are on NT/Win2K/XP/2003 You could try WMI... > This is hacked together from my build system and untested but > it should give you the general idea. Some references here: > http://msdn.microsoft.com/library/default.asp?url=/library/en- > us/wmisdk/ > wmi/win32_networkadaptersetting.asp > > Paul > > > use Win32::OLE > > my $x = > Win32::OLE->GetObject("WinMgmts://$ENV{COMPUTERNAME}/root/cimv2"); > my $y = $x->ExecQuery(qq(SELECT * FROM Win32_NetworkAdapter > WHERE AdapterType = "Ethernet 802.3")); > > my $NewIP = "192.168.0.1"; > my $NewMask = "255.255.255.0"; > my $NewGateway = "192.168.0.254"; > my $NewDNS = [ ("192.168.0.10","192.168.0.50" ]; > > foreach my $adapter (in $y) { > my $settings = > $adapter->Associators_(undef,"Win32_NetworkAdapterConfiguration"); > for my $setting (in $settings) { > next unless $setting->{IPEnabled} == 1; > # We only get to here if the adapter is > ethernet and ip enabled > my $IPAddress = $setting->{IPAddress}->[0]; > my $Mask = $setting->{IPSubnet}->[0]; > my $Gateway = $setting->{DefaultIPGateway}->[0]; > my $DHCPState = $setting->{DHCPEnabled}; > my $AdapterIndex = $adapter->{Index}; > my $AdapterName = $adapter->{Description}; > > print "\t\tOld ip details for adapter $ApapterIndex > ($AdapterName): IP - $IPAddress DHCP - $DHCPState\n"; > > my $result = $setting->EnableStatic([ $NewIP ], [ > $NewMask ]); > print "\t\tSet ip to $NewIP (result $result)\n"; > > my $result = $setting->SetGateways([ $NewGateway ], [ 1 > ]); > print "\t\tSet gateway to $NewGateway (result > $result)\n"; > > my $result = $setting->SetDNSServerSearchOrder($NewDNS); > print "Set DNS servers to " . join(",",@$NewDNS) . > "(result $result)\n"; > > exit; > } > } > > -----Original Message----- > > ***************************************************************** > Gloucester Research Limited believes the information > provided herein is reliable. While every care has been > taken to ensure accuracy, the information is furnished > to the recipients with no warranty as to the completeness > and accuracy of its contents and on condition that any > errors or omissions shall not be made the basis for any > claim, demand or cause for action. > ***************************************************************** > > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Marcos Lorenzo de Santiago > Sent: 28 February 2005 09:59 > To: Perl-Win32-Admin > Cc: Perl-Win32-Users > Subject: Change network interface parameters via Perl > > I need to change the network interface parameters (ie: IP, > Gateway, Mask, > DHCP...) via Perl, is there any module I could use? and/or > documentation on it? I've been trying to use netsh command > from Windows XP and parsing its output but I guess there > might be another prettier way to do this. > > > TIA. > Regards, > m4c. > > -- > ,------------------------------------------------------------- > ---------. > | Mathematics is the only science where one never knows what > | > | one is talking about nor whether what is said is true. > | > | -- Russell > | > |------------------------------------------------------------- > ---------| > | Labs. Technician | > | > | Department of Telematic Engineering | Debian > GNU/Linux Powered | > | Universidad Carlos III de Madrid | > | > |-------------------------------------------| > .--. | > | | > |o_o | | > | _________ | .''`. > |:_/ | | > | |~~ @| Marcos Lorenzo de Santiago | : :' : // > \ \ | > | | ==== | E-mail: [EMAIL PROTECTED] | `. `' (| > | ) | > | | ==== | Telephone: (+34) 91-624-9959 | `- /'\_ > _/`\ | > | |_________| Web: www.it.uc3m.es/marcos | > \___)=(___/ | > | | > | > `------------------------------------------------------------- > ---------' > > > _______________________________________________ > Perl-Win32-Users mailing list > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > _______________________________________________ Perl-Win32-Admin mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
