Jump to content

Network configuration UDF


jguinch
 Share

Recommended Posts

spudw2k : i thought about adding a $remotecomputer parameter, but it will be limited to only some functions (as you said). I preferred not to do, to be consistent in all functions.

Now, if it can be useful to someone, I will.

The flushdns could be affected to, maybe with Win32_Process and the Create() method.

Link to comment
Share on other sites

If I were to do it I would add an optional $computer paramter as the last param to the "remote" functions and modify the WMI call and REG funcs to use it.

Func _GetNetworkAdapterInfos($sNetAdapter = "", $sComputer = @ComputerName)
 Local $objWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\CIMV2")
Func _GetNetworkAdapterList($sComputer = @ComputerName)
...
$sGuid = RegEnumKey("\\" & $sComputer & "\HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces", $i)

etc...

 

edit:
As far as performing the _FlushDNS using WMI (Win32_Process.Create), I haven't used that is a long time and am not thinking of an easy way to retrieve some sort of return code for sucess or failure.  Might not be that important as the expected results from a DNS Flush are pretty clear cut and dry, but just from a good coding perspective some validation is always preferred.

Edited by spudw2k
Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...
  • 10 months later...

Hi jguinch, thanks for a very useful UDF library.

I think I've found an issue with the _GetNetworkInfos function. When I tried it on Windows 7 Prof  64bit & Windows 10 Prof. 64 bit, I got a COM error on line 457, which contains:

                $aInfos[$n - 1][22] = _Array2String( ($objNetAdapterConfig.DNSDomainSuffixSearch) , ",")


According to https://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx, the property is :  string   DNSDomainSuffixSearchOrder[];

Changing the line to

                $aInfos[$n - 1][22] = _Array2String( ($objNetAdapterConfig.DNSDomainSuffixSearchOrder) , ",")

made it work for me.

Link to comment
Share on other sites

  • 2 weeks later...

Just want to say this is nice, all i had to do was coment out the arraydisplay, else it would show every time, and i didnt need that.

Thanks for UDF.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

Example of what works for me:

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=dns.ico
#AutoIt3Wrapper_Res_Icon_Add=dns.ico
#pragma compile(UPX, false)
#pragma compile(ProductVersion, 1.0)
#pragma compile(FileVersion, 1.0)
#pragma compile(x64, false)
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include 'AutoItConstants.au3'
#include "network.au3"
FileInstall("dns.ico", @TempDir & "\dns.ico", 1)
FileInstall("dns.au3", @TempDir & "\dns.au3", 1)
FileInstall("network.au3", @TempDir & "\network.au3", 1)
Local $infos = _GetNetworkAdapterList()
;MsgBox(64, '', $infos[1][1])
Run('netsh dnsclient add dnsservers name="' & $infos[1][1] & '" address=8.8.8.8 index=1 validate=yes', '', @SW_HIDE)
Run('netsh dnsclient add dnsservers name="' & $infos[1][1] & '" address=8.8.4.4 index=2 validate=yes', '', @SW_HIDE)
Exit

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • 1 month later...

sorry for the late response for windows 10 change "Local Area Connection" to "Ethernet", let me know when you will update the UDF

Func AddStaticIPInfo($NewIP, $Gateaway)
Local $subnetMask = "255.255.255.192", $DnsPrimary = "10.1.246.40", $DnsSecondary = "10.224.41.40"
        Local $WinsPrimary = " 10.1.40.68", $WinsSecondary = "10.224.40.68"


        RunWait('netsh interface ipv4 set address name="Local Area Connection" source=static address=' & $NewIP & ' mask=' & $subnetMask & ' gateway=' & $Gateaway, "", @SW_HIDE) ; gwmetric=1
        ConsoleWrite("newIPtest" & $NewIP)
        RunWait('netsh interface ip set dns name= "Local Area Connection" source="static" address= ' & $DnsPrimary, "", @SW_HIDE)
        RunWait('netsh interface ip add dns name="Local Area Connection" index=2 addr=' & $DnsSecondary, "", @SW_HIDE)
        RegWrite($sHKLMRoot & '\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'SearchList', 'REG_SZ', 'yahoo.com,amazon.com,google.com')
;~RunWait(@Comspec & ' /c Reg Add HKLM\system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f')


        RunWait('netsh interface ip set winsservers name= "Local Area Connection" source="static" address= ' & $WinsPrimary, "", @SW_HIDE)
        RunWait('netsh interface ip add winsservers name="Local Area Connection" index=2 addr=' & $WinsSecondary, "", @SW_HIDE)

    EndIf
    
    endfunc

 

Edited by antonioj84
error
Link to comment
Share on other sites

@antonioj84 : for my question in #32 :

On 05/04/2017 at 7:26 PM, antonioj84 said:

There are 3 area that did not work for me  adding DNS, WINS and  WINS Suffixes.

My question was : Can you post the code you used with my UDF for this ? I cannot reproduce the issue. Are you sure you used #RequireAdmin at the top of the script ?
Also, there is no function to add Wins suffixes, you meant DNS Suffixes ? You can do it with _SetDNSSuffixSearchOrder  (fixed now)

Example :

#RequireAdmin

#Include "Network.au3"

Local $aDns = ["192.168.1.10", "192.168.1.11"]
Local $aDnsDomains = ["mydomain.local", "myotherdomain.local"]
Local $sAdapter = "Local Area Connection"

_SetDNSServerSearchOrder($sAdapter, $aDns)
_SetDNSSuffixSearchOrder($aDnsDomains)

 

Link to comment
Share on other sites

RunWait('netsh interface ip set winsservers name= "Local Area Connection" source="static" address= ' & $WinsPrimary, "", @SW_HIDE)
 RunWait('netsh interface ip add winsservers name="Local Area Connection" index=2 addr=' & $WinsSecondary, "", @SW_HIDE)

@jguinch

 I did not use your UDF per say, however I took some of your ideas, what I was looking for was suffixes , dns and wins.  The code I posted above  showed how to do that.  I use "#requireAdmin"

 Thanks for making the changes and the update on your UDF.  I will use your UDF in the future.

 

see the link

 

Edited by antonioj84
ok
Link to comment
Share on other sites

@ @jguinch  about your print udf I basically want to check if a printer exist then change the Current IP address to a new IP address

can I do this ?

if _printmgrPrinterExist("myprinter") then
_PrintMgr_RemoveTCPIPPrinterPort("192.123.114.14")
_PrintMgr_AddTCPIPPrinterPort("10.229.114.1)
endif

if _printmgrPrinterExist("myprinter") then
_printMgr_SetPrinterPort("10.229.114.1)
endif

 

Link to comment
Share on other sites

@ jguinch

You may consider adding hostname ,  workgroup , description to make it complete

Func AddPOSname($computer)
     $name =  $sComputerName
    $sWorkGroup = "WORKGROUP"
    $CMD = 'net config server /srvcomment:"'




    RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName", "REG_SZ", StringUpper($name))
    RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", StringUpper($name))
    RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", StringUpper($name))
    RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", StringUpper($name))

    RunWait(@ComSpec & " /c " & $CMD & StringUpper($name), "", "", @SW_HIDE) ; adding computer description name


    If @OSArch = "x64" Then
        DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection

        RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & StringUpper($sWorkGroup) & '"}"', "", @SW_HIDE) ; adding to workgroup

        DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection
    Else

        RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & StringUpper($sWorkGroup) & '"}"', "", @SW_HIDE) ; adding to workgroup

    EndIf

    

EndFunc   ;==>Addhostname

 

Edited by antonioj84
ok
Link to comment
Share on other sites

@antonioj84 : for the Printer UDF, please post the message in the good topic, it has no sense here.

8 hours ago, antonioj84 said:

 I did not use your UDF per say, however I took some of your ideas, what I was looking for was suffixes , dns and wins.  The code I posted above  showed how to do that.  I use "#requireAdmin"

Ok, so you didn't try  it, and you say it doesn't work ???

 

 

7 hours ago, antonioj84 said:

You may consider adding hostname ,  workgroup , description to make it complete

No, I do not consider it. It's a network configuration UDF, that's all.

Link to comment
Share on other sites

First off, thank you for a very nice UDF. I am trying to incorporate it into a script that displays a lot of information about the machine for use in our helpdesk information gathering for trouble tickets. I do have a question, though. Why is it that when I use the _GetNetworkAdapterInfos() that I only get a return on the active NIC?

As an example, I have a wireless and wired NICs as well as a VPN adapter and bluetooth adapter listed when I perform _GetNetworkAdapterList(). But when I run the _GetNetworkAdapterInfos() immediately afterward, as in your default demonstration script, it only shows the information for my wireless NIC, which is active. It does not show any information on any other network devices. I should still be able to get MAC addresses, shouldn't I? I know there are other ways to do this but just curious why it only shows the active device.

I am running Windows 10 Enterprise 64 bit on a Lenovo W530.

Who lied and told you life would EVER be fair?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...