Jump to content

Recommended Posts

Posted

MsgBox(0,"Network IP","Your Correct Network IP Address : " & GetLanIP())

Func GetLanIP()
Local $colItems = ""
Local $strComputer = "localhost"
Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20)
If IsObj($colItems) then
   For $objItem In $colItems
       if (StringLen($objItem.IPAddress(0)) > 3) AND (StringLen($objItem.DefaultIPGateway(0)) > 3) Then
If @IPAddress1 = $objItem.IPAddress(0) Then Return @IPAddress1
If @IPAddress2 = $objItem.IPAddress(0) Then Return @IPAddress2
If @IPAddress3 = $objItem.IPAddress(0) Then Return @IPAddress3
If @IPAddress4 = $objItem.IPAddress(0) Then Return @IPAddress4
      Endif
   Next
Else
Return @IPAddress1 ; if you dont have Gateway
Endif
EndFunc

Posted (edited)

Forgive my ignorance but is this any different from

TCPNameToIP(@ComputerName)
, the reason I ask is because i been bashing my brains out with a limp lettuce trying to get something similar for Gateway, DNS etc, I had to resort to using dos commands and wandered if this could be used in stead.

TCPStartup()
Global $local_IP = TCPNameToIP(@ComputerName)
If @error Then
$local_IP = "No Network"
EndIf
TCPShutdown()

Func _welcome()
$local_domain = @LogonDNSDomain
$domain_server = @LogonServer
$gateway = ipconfig("Default Gateway")
$dns_server = ipconfig("DNS Servers")
;$DHCP_server = ipconfig("DHCP Server")
;$subnet_mask = ipconfig("Subnet Mask")
MsgBox(64, "Local IP: " & $local_IP & " DNS: " & $dns_server & " Gateway: " & $gateway, "Welcome " & @UserName & " to the " & $local_domain & " Network" & @CRLF & @CRLF & "you seem to be running " & @OSVersion & " Version OS " & @OSArch & @CRLF & @CRLF & "If you have any problems or questions with your account please contact Computer Facilities support on 0414-533784" & @CRLF & @CRLF & "Enjoy" & @CRLF & @CRLF & "Logon script in " & $operation & " from " & @ComputerName & " using Server " & $domain_server)
EndFunc   ;==>_welcome

Func ipconfig($lookfor)
;http://www.autoitscript.com/forum/index.php?showtopic=82733&st=0&p=625302&hl=IP%20gateway&fromsearch=1&#entry625302
;thanks to NBJ I belive for this.
;Possibly not very usful if more than 1 active IP is present?
$cmd = Run(@ComSpec & " /c ipconfig /all", "", @SW_HIDE, 2 + 4)
$Result = ""
While 1
  $line = StdoutRead($cmd)
  If @error Then Return "Error"
  If StringInStr($line, $lookfor) Then ExitLoop
WEnd
$Data = StringSplit(StringStripWS($line, 7), $lookfor, 1)
$Data = StringSplit($Data[2], ":", 1)
$Data = StringStripWS($Data[2], 7)
ConsoleWrite(@CR & $lookfor & "=" & $Data)
;MsgBox (16,$lookfor, $Data)
Return $Data
EndFunc   ;==>ipconfig

I been looking at ways to make this more robust, any ideas.. the above is just the relevent snippets of code not the whole I can post it if required..

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Posted

TCPNameToIP(@ComputerName) get alway @ipaddress1

if you have 2 or more network connections (Bluetooth pan network, Ceel Phone connect etc.) you get always first network name ip.

Networks:

1- Bluetooth pan network , 10.0.2.1

2- Real Network, 192.168.0.1

3- Other Devices network, 9.0.1.1

TCPNameToIP(@ComputerName) = 10.0.2.1

@ipaddress1 = 10.0.2.1

GetLanIP() = 192.168.0.1 (if you have network gateway, like adsl modem etc.)

Posted

ahh ok that makes sence, any ideas on how one might get the DNS and Gateway address from the required IP found with GetLanIP()?

[topic='115020'] AD Domain Logon Script[/topic]

Posted

I did this and this seems to work, did i understand your logic correctly?

Func GetLanGW()
 ;http://www.autoitscript.com/forum/index.php?showtopic=109887&st=0&gopid=772563&#entry772563
 ;Thanks to Phodexis for this.
 Local $colItems = ""
 Local $strComputer = "localhost"
 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
 Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20)
 If IsObj($colItems) Then
  For $objItem In $colItems
   If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DefaultIPGateway(0)) > 3) Then
    If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
    If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
    If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
    If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
   EndIf
  Next
 Else
  Return @IPAddress1 ; if you dont have Gateway
 EndIf
EndFunc   ;==>GetLanGW

[topic='115020'] AD Domain Logon Script[/topic]

Posted

Thanks a real life saver, this is a bit basic as I really have only adapted what I seen from your example.

Func GetLanIP()
 ;http://www.autoitscript.com/forum/index.php?showtopic=109887&st=0&gopid=772563&#entry772563
 ;Thanks to Phodexis for this.
 ;http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx for the Win32_NetworkAdapterConfiguration Class
 Local $colItems = ""
 Local $strComputer = "localhost"
 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
 Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20)
 If IsObj($colItems) Then
  For $objItem In $colItems
   If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DefaultIPGateway(0)) > 3) Then
    If @IPAddress1 = $objItem.IPAddress(0) Then Return @IPAddress1
    If @IPAddress2 = $objItem.IPAddress(0) Then Return @IPAddress2
    If @IPAddress3 = $objItem.IPAddress(0) Then Return @IPAddress3
    If @IPAddress4 = $objItem.IPAddress(0) Then Return @IPAddress4
   EndIf
  Next
 Else
  Return @IPAddress1 ; if you dont have Gateway
 EndIf
EndFunc   ;==>GetLanIP

Func GetLanGW()
 Local $colItems = ""
 Local $strComputer = "localhost"
 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
 Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20)
 If IsObj($colItems) Then
  For $objItem In $colItems
   If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DefaultIPGateway(0)) > 3) Then
    If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
    If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
    If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
    If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.DefaultIPGateway(0)
   EndIf
  Next
 Else
  Return @IPAddress1 ; if you dont have Gateway
 EndIf
EndFunc   ;==>GetLanGW

Func GetLanDNS()
 Local $colItems = ""
 Local $strComputer = "localhost"
 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
 Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20)
 If IsObj($colItems) Then
  For $objItem In $colItems
   If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DNSServerSearchOrder(0)) > 3) Then
    If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0)
    If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0)
    If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0)
    If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.DNSServerSearchOrder(0)
   EndIf
  Next
 Else
  Return @IPAddress1 ; if you dont have DNS
 EndIf
EndFunc   ;==>GetLanDNS

Func GetLanDHCP()
 Local $colItems = ""
 Local $strComputer = "localhost"
 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
 Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20)
 If IsObj($colItems) Then
  For $objItem In $colItems
   If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.DHCPServer(0)) > 3) Then
    If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0)
    If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0)
    If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0)
    If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.DHCPServer(0)
   EndIf
  Next
 Else
  Return @IPAddress1 ; if you dont have a DHCP Server
 EndIf
EndFunc   ;==>GetLanDHCP

Func GetLanSubnet()
 Local $colItems = ""
 Local $strComputer = "localhost"
 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
 Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20)
 If IsObj($colItems) Then
  For $objItem In $colItems
   If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.IPSubnet(0)) > 3) Then
    If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0)
    If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0)
    If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0)
    If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.IPSubnet(0)
   EndIf
  Next
 Else
  Return @IPAddress1 ; if you dont have IPSubnet
 EndIf
EndFunc   ;==>GetLanSubnet
I know its a bit clumsy but it seems to work and just so much better than the code i was using before.. I would appreciate it if you could just check to make sure that I have understood your code sufficiently so at least I'm not make any serious blunders.

[topic='115020'] AD Domain Logon Script[/topic]

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
  • Recently Browsing   0 members

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