Jump to content

Help with some queries with my server and AutoIt


Recommended Posts

I uses this script in order to get Name of my Server and IPADRESS

#include <Constants.au3>

;Récupere le nom et l'IP du S2

$process_id = Run(@ComSpec & " /c nslookup.exe 127.0.0.1 ","", @SW_HIDE,$STDOUT_CHILD)

$line = StdoutRead($process_id)

if StringLen($line)>11 then

$myarray = StringRegExp(StringLower($line),".*(w-013[0-9]{4}[a-z]-).*", 1)

if (StringLen($myarray[0]) >10) then

$S2_name=$myarray[0]&"2"

Msgbox (0,"test",$s2_name)

EndIf

endif

$process_id = Run(@ComSpec & " /c nslookup.exe "& $s2_name ,"", @SW_HIDE,$STDOUT_CHILD)

$line = StdoutRead($process_id)

if StringLen($line)>11 then

$myarray = StringRegExp(StringLower($line),"172.*.*.163",1)

if (StringLen($myarray[0]) >5) then

$S2_ip=$myarray[0]

Msgbox (0,"test",$s2_ip)

EndIf

endif

How to verify if my server Name is like AD-*

How to verify if my IP Begins by 172.*.*.*

Edited by potitpanda
Link to comment
Share on other sites

We need more info. I'm thinking Nslookup may not be the best option here.

This lines don't make sense to me, why aren't you using a regular expression that takes the server name no matter what format?

if StringLen($line)>11 then

$myarray = StringRegExp(StringLower($line),".*(w-013[0-9]{4}[a-z]-).*", 1)

if (StringLen($myarray[0]) >10) then

Link to comment
Share on other sites

I uses this script in order to get Name of my Server and IPADRESS

#include <Constants.au3>

;Récupere le nom et l'IP du S2

$process_id = Run(@ComSpec & " /c nslookup.exe 127.0.0.1 ","", @SW_HIDE,$STDOUT_CHILD)

$line = StdoutRead($process_id)

if StringLen($line)>11 then

$myarray = StringRegExp(StringLower($line),".*(w-013[0-9]{4}[a-z]-).*", 1)

if (StringLen($myarray[0]) >10) then

$S2_name=$myarray[0]&"2"

Msgbox (0,"test",$s2_name)

EndIf

endif

$process_id = Run(@ComSpec & " /c nslookup.exe "& $s2_name ,"", @SW_HIDE,$STDOUT_CHILD)

$line = StdoutRead($process_id)

if StringLen($line)>11 then

$myarray = StringRegExp(StringLower($line),"172.*.*.163",1)

if (StringLen($myarray[0]) >5) then

$S2_ip=$myarray[0]

Msgbox (0,"test",$s2_ip)

EndIf

endif

How to verify if my server Name is like AD-*

How to verify if my IP Begins by 172.*.*.*

i'm having a duh moment here, or just a nonexperienced one, why not use:

ConsoleWrite(@IPAddress1 & @CRLF)
ConsoleWrite(@IPAddress2 & @CRLF)
ConsoleWrite(@IPAddress3 & @CRLF)
ConsoleWrite(@IPAddress4 & @CRLF)
ConsoleWrite(@ComputerName & @CRLF)

data from those? That will give you the ip addresses of all of the network adapters (up to 4) and your host name on the computer you run it on. Since your doing a nslookup on 127.0.0.1, i'd assume you are running this on your own machine.

Now, if you are doing it on a remote machine, ok then it'd make sense. I'm just wondering tho.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Hi,

there is one thing you need to start:

1. Having the IP you can get the Name

2. Having the name you can get the IP.

What do you want?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

This should work for checking the local machine. I suppose you could change localhost in the WMI query to run on remote machines.

#include <inet.au3>

;Retrieve IP address of primary DNS server from the primary network adapter
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE index=1", "WQL", 0x10 + 0x20)
If IsObj($colItems) Then
    For $objItem In $colItems
        $strDNSServerSearchOrder = $objItem.DNSServerSearchOrder(0)
        
        ;Reverse lookup the DNS IP address to find its hostname
        TCPStartup()
        $sResult = _TCPIpToName($strDNSServerSearchOrder)
        
        If @error Then
            MsgBox(0, "_TCPIpToName()", "@error = " & @error & @LF & "@extended = " & @extended)
        Else
            MsgBox(0, "", "DNS server address: " & $strDNSServerSearchOrder & @CRLF & "DNS hostname: " & $sResult)
            
            If StringLeft($sResult, 6) = "AD-013" AND StringLeft($strDNSServerSearchOrder, 3) = "172" Then
                MsgBox(0, "", "VALID")
            Else
                MsgBox(0, "", "INVALID")
            EndIf
        EndIf
    Next
Else
    MsgBox(0, "WMI Output", "No WMI Objects Found for class: Win32_NetworkAdapterConfiguration")
EndIf
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...