Menu

0.22

Zangune
:::::::::::::::::::::::::
::                     ::
:: Copyright at bottom ::
::   search @License   ::
::                     ::
:::::::::::::::::::::::::
::
@ECHO Off
::
:: Start delayed expansion, it's needed by @FindMac, @FindIp and @FindPorts
:: routines. No end.
::
SETLOCAL EnableDelayedExpansion
::
:: Find Windows version through registry, differences between Windows versions
:: exist, in example XP is "Microsoft Windows XP" but Windows 8 is "Windows 8",
:: without "Microsoft".
:: @FindWindowsVersion
::
FOR /F "TOKENS=3*" %%V IN ('
    REG QUERY
        "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
            /v ProductName
    ^|FIND "REG_SZ"'
) DO (
    SET WindowsVersion=%%W
)
::
:: Clean up, remove "Windows", if present.
::
SET WindowsVersion=%WindowsVersion:Windows =%
::
:: Clean up, remove everything but the first word.
::
FOR /F "TOKENS=1" %%C IN (
    "%WindowsVersion%"
) DO (
    SET WindowsVersion=%%C
)
::
:: Find Windows bitness by checking %ProgramFiles(x86)% environment variable
:: existence.
:: @FindBitness
::
IF DEFINED ProgramFiles(x86) (
    SET WindowsNumberOfBits=64
) ELSE (
    SET WindowsNumberOfBits=32
)
::
:: Find the registry key that determines the eMule config folder position and
:: store it in a temporary variable.
:: If the registry key is not found, hide errors.
:: @FindRegistryKey
::
FOR /F "TOKENS=3*" %%P IN ('
    REG QUERY
        "HKEY_CURRENT_USER\Software\eMule"
            2^>NUL
    ^|FIND "UsePublicUserDirectories"'
) DO (
    SET eMuleRegistryConfigValue=%%P
)
::
:: Dummy variable, this way the cycle below won't fail even if the registry key
:: above is missing.
::
IF NOT DEFINED eMuleRegistryConfigValue (
    SET eMuleRegistryConfigValue=0x3
)
::
:: Strip 0x from the value.
::
SET eMuleRegistryConfigValue=%eMuleRegistryConfigValue:0x=%
::
:: Find the config folder, the default folder is in Program Files.
:: It checks bitness, too.
:: 0=each user has its own config directory, 1=users share the config directory
:: and downloads, 2=config directory in the executable directory.
:: If Windows version is older than Windows Vista, 1 has the same effect as 2.
:: I added a nonexistent (among eMule registry keys) -1 to point to "Drive:"
:: @FindConfigFolder
::
IF %eMuleRegistryConfigValue% LSS 2 (
    IF %eMuleRegistryConfigValue% LSS 1 (
        IF %eMuleRegistryConfigValue% LSS 0 (
            SET eMuleConfigFolderRoot=%HomeDrive%
        ) ELSE (
            IF %WindowsVersion%==XP (
                SET eMuleConfigFolderRoot=%AppData%
            ) ELSE (
                SET eMuleConfigFolderRoot=%LocalAppData%
            )
        )
    ) ELSE (
        IF %WindowsVersion%==XP (
            SET eMuleConfigFolderRoot=%ProgramFiles%
        ) ELSE (
            SET eMuleConfigFolderRoot=%ProgramData%
        )
    )
) ELSE (
    IF %WindowsNumberOfBits% LSS 64 (
        SET eMuleConfigFolderRoot=%ProgramFiles%
    ) ELSE (
        SET "eMuleConfigFolderRoot=%ProgramFiles(x86)%"
    )
)
SET eMulePreferencesIni="%eMuleConfigFolderRoot%\eMule\config\preferences.ini"
::
:: If preferences.ini is in current folder use this instead of the found one,
:: output hidden.
::
VERIFY>NUL
DIR/B "%~dp0"^
    |FIND "preferences.ini">NUL
IF NOT ERRORLEVEL 1 (
    SET eMulePreferencesIni="%~dp0preferences.ini"
)
::
:: Replace with the user preferences.ini, if set, instead of the found one.
::
SET eMuleProposedPreferencesIni=%*
IF DEFINED eMuleProposedPreferencesIni (
    SET eMulePreferencesIni="%eMuleProposedPreferencesIni%"
)
::
:: Unset to avoid an old variable to mess up next cycle.
::
SET eMuleUDPPort=
::
:: First port occurrence is TCP, second is UDP, then the others.
:: FOR output is Port=<number> or UDPPort=<number>, so the SET %%P trick.
:: It needs delayed expansion.
:: @FindPorts
::
FOR /F "DELIMS=" %%P IN ('
    TYPE %eMulePreferencesIni%
        ^|FINDSTR "Port="'
) DO (
    IF NOT DEFINED eMuleUDPPort (
        SET eMule%%P
        SET eMuleTCPPort=!eMulePort!
    )
)
::
:: Filters MAC addresses from IPCONFIG /All command, comma separated.
:: It needs delayed expansion.
:: @FindMac
::
FOR /F "TOKENS=2 DELIMS=:" %%T IN ('
    IPCONFIG/ALL
        ^|FINDSTR/ER
            /C:"[ ]..\-..\-..\-..\-..\-.."'
) DO (
    SET MacAddresses=!MacAddresses!,%%T
)
::
:: Strip out all the spaces.
::
SET MacAddresses=%MacAddresses: =%
::
:: Strip first comma, this is a bit lame to me, see @FindIp routine.
::
SET MacAddresses=%MacAddresses:~1%
::
:: Substitute dashes with colons.
::
SET MacAddresses=%MacAddresses:-=:%
::
:: Make MAC addresses routine output lowercase.
::
SET MacAddresses=%MacAddresses:A=a%
SET MacAddresses=%MacAddresses:B=b%
SET MacAddresses=%MacAddresses:C=c%
SET MacAddresses=%MacAddresses:D=d%
SET MacAddresses=%MacAddresses:E=e%
SET MacAddresses=%MacAddresses:F=f%
::
:: Find gateway, this is shown at bottom of the ROUTE PRINT output, but for now
:: I assume it is the first occurrence after 0.0.0.0 in ROUTE PRINT.
:: Regression to 0.16, as a temporary fix.
:: @FindGateway
::
FOR /F "TOKENS=3" %%G IN ('
    ROUTE PRINT
        ^|FINDSTR "\<0.0.0.0\>"'
) DO (
    SET Gateway=%%G
)
::
:: Filters local IP addresses from IPCONFIG command. It needs delayed expansion
:: @FindIp
::
FOR /F "TOKENS=2 DELIMS=:" %%I IN ('
    IPCONFIG
        ^|FIND "IP"
            ^|FINDSTR/V ":.*:"'
) DO (
    SET LocalIPAddresses=!LocalIPAddresses!,%%I
)
::
:: Strip out all the spaces.
::
SET LocalIPAddresses=%LocalIPAddresses: =%
::
:: Strip first comma, this is a bit lame to me, see @FindMac routine.
::
SET LocalIPAddresses=%LocalIPAddresses:~1%
::
:: Print into Notepad.
::
ECHO computer=%ComputerName% Windows %WindowsVersion% %WindowsNumberOfBits%bit^
 ip=%LocalIPAddresses% mac=%MacAddresses% router= http://%Gateway%^
 tcp=%eMuleTCPPort% udp=%eMuleUDPPort% >%TMP%\ArzFoundData.txt
NOTEPAD %TMP%\ArzFoundData.txt
::
EXIT

The following text will not be shown because of the EXIT command before, but it
is part of arz.bat and it is needed by GNU General Public license version 3, so
it cannot be stripped out.

@License

Copyright (C) 2013-2025  Zangune

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>

Zangune Nick@Host Nick=Zangune Host=Users.SourceForge.Net
http://sf.net/u/zangune

Related

Code: draft
Code: main
Forum: Copy and paste from Code may not respect tabs and newlines
Issues: #16