jdv79 has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know of a way to alter the properties of LAN network interfaces in w2k? I know this is not a purely PERL question but the actions need to be performed through PERL so its kind of relevant. Is there a module for this sort of thing or is there a cmdline util of some sort? I tried netsh which is a little cmdline util found on w2k systems(maybe other win32 as well) that allows you to change most properties of dialup interfaces but not LAN. I am trying to do this because one of my clients has two connections to the Inet, a cable modem and a 384K DSL line. I want to be able to, on the w2k router(dont laugh too hard-its not my call on this one), enable and disable interfaces and moves routes around to deal with line outages that happen semi-regularly. A minute convergance time is more than fine so its not a critical network app. but I need to make it automatic. Obviously I can change routes no big deal. Its altering the states(enabled/disabled) and properties of the interfaces thats proving to be difficult.

Thanks, Justin

Replies are listed 'Best First'.
Re: w2k networking
by t0mas (Priest) on Sep 19, 2002 at 08:14 UTC
    I've looked into automagically enable/disable network connections before. Heres what I came up with.

    First I aimed for the registry, it seems like disable a connection clears the NTEContextList of the interface and reduces a reference count (Yes!) to the interface. Enable it sets a unique hex counter on NTEContextList and increases the reference count. It probably does more that that, so I decided not to fiddle with it.

    I decided to go for a solution using the Win32::GuiTest module and emulate a user (Me) doing it.

    Here is my code, you'll probably need to modify it to match your icon positions and maybe increase/decrease the sleep values.
    #!/usr/bin/perl -w use strict; use Win32::GuiTest qw(SetForegroundWindow FindWindowLike GetWindowText + SendKeys); use vars qw(@windows); #- Check for open ncpa.cpl @windows = FindWindowLike(0, "Network and Dial-up Connections", "", 0, + 1); #- Close all open ones for (@windows) { SetForegroundWindow($_); sleep 1; SendKeys("%{F4}"); } #- Open a new one system ("cmd /c start ncpa.cpl"); sleep 2; @windows = FindWindowLike(0, "Network and Dial-up Connections", "", 0, + 1); SetForegroundWindow($windows[0]); sleep 1; #- Now, navigate to the icon you want with right arrow keys #- Mine is the second icon so I need only one keystroke SendKeys("{RIGHT}"); #- Open the right klick menu and press enable/disable SendKeys("+{F10}{DOWN}~"); #- Wait a while (enabling takes some time) sleep 15; #- Close window SendKeys("%{F4}");
    Good luck,

    /brother t0mas
      I appreciate the help! Its defintiely not a pure method(thats not anybodies fault but m$'s IMHO) but it will probably get the job done. Funky way of having to go about what is such a simple task in a *nix evironment. On one hand I am surprised and on the other I expected it to be like this-it almost always is with windows:) -Justin
Re: w2k networking
by Marza (Vicar) on Sep 19, 2002 at 05:52 UTC

    I have not tried it myself on w2k. Did for NT. You might be able to use the TieRegisitry module and attempt a change in the Registry. I once used it to change the Wins address for a bunch of machines.

    The two places to look would be NetBT and TCPIP interfaces in the Service of CurrentControlSet.

    As to other mods? I am not sure myself. Maybe one of the more "seasoned" Monks may know something

    Good luck