Analisi Rete di Zangune Code
Find information to forward eMule ports
Status: Alpha
Brought to you by:
zangune
::::::::::::::::::::::::::::::
:: Copyright info at bottom ::
::::::::::::::::::::::::::::::
::
@ECHO Off
::
:: Start delayed expansion, it's needed by GetMac and GetIp, no end
::
SETLOCAL EnableDelayedExpansion
::
:: Find Windows version through registry, differences between Windows
:: versions exists, in exaple XP is "Microsoft Windows XP" but Windows 8
:: is "Windows 8", without "Microsoft", futureproof
::
FOR /F "TOKENS=3*" %%V IN (
'REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName
^|FIND "REG_SZ"'
) DO (
SET TempWindowsVersion=%%W
)
::
:: Clean up, remove "Windows", if present
::
SET TempWindowsVersion=%TempWindowsVersion:Windows =%
::
:: Clean up, remove anything but the first word
::
FOR %%C IN (
%TempWindowsVersion%
) DO (
IF NOT DEFINED WindowsVersion (
SET WindowsVersion=%%C
)
)
::
:: Find Windows bitness by checking Program Files (x84) directory existence
::
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.
::
FOR /F "TOKENS=3*" %%P IN (
'REG QUERY "HKEY_CURRENT_USER\Software\eMule" 2^>NUL
^|FIND "UsePublicUserDirectories"'
) DO (
SET TempRegistryConfigNumericValue=%%P
)
::
:: Dummy variable, this way the cycle below won't fail even if the
:: registry key above is missing
::
IF NOT DEFINED TempRegistryConfigNumericValue (
SET TempRegistryConfigNumericValue=0x3
)
::
:: Strip 0x from the value
::
SET RegistryConfigNumericValue=%TempRegistryConfigNumericValue:0x=%
::
:: Complex if cycle - FindConfig
:: 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.
::
IF %RegistryConfigNumericValue% LSS 2 (
IF %RegistryConfigNumericValue% LSS 1 (
IF %RegistryConfigNumericValue% LSS 0 (
IF %WindowsNumberOfBits% LSS 64 (
SET eMuleConfigFolderRoot=%ProgramFiles%
) ELSE (
SET "eMuleConfigFolderRoot=%ProgramFiles(x86)%"
)
) 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 eMuleConfigFolder=%eMuleConfigFolderRoot%\eMule\config
SET PreferencesIni="%eMuleConfigFolder%\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 PreferencesIni="%~dp0preferences.ini"
)
::
:: Replace with the user preferences.ini, if set, instead of the found one.
::
SET ProposedPreferencesIni=%*
IF DEFINED ProposedPreferencesIni (
SET PreferencesIni="%ProposedPreferencesIni%"
)
::
:: First port occurrence is TCP, second is UDP, then the others.
:: FOR output is Port=<number> so the SET %%P trick.
::
FOR /F "DELIMS=" %%P IN (
'TYPE %PreferencesIni%
^|FINDSTR "Port="'
) DO (
IF NOT DEFINED UDPPort (
SET %%P
)
)
::
:: Filters MAC Address from IpConfig /All command, comma separated
:: needs delayed expansion - GetMac
::
FOR /F "TOKENS=2 DELIMS=:" %%T IN (
'IPCONFIG/ALL
^|FINDSTR/ER /C:"[ ]..\-..\-..\-..\-..\-.."'
) DO (
SET TempMac=!TempMac!,%%T
)
::
:: Strip out all the spaces
::
SET TempMac=%TempMac: =%
::
:: Strip first comma, this is a bit lame to me, see GetIp
::
SET TempMac=%TempMac:~1%
::
:: Substitute dashes with colons
::
SET MacAddress=%TempMac:-=:%
::
:: Make output lowercase
::
SET MacAddress=%MacAddress:A=a%
SET MacAddress=%MacAddress:B=b%
SET MacAddress=%MacAddress:C=c%
SET MacAddress=%MacAddress:D=d%
SET MacAddress=%MacAddress:E=e%
SET MacAddress=%MacAddress:F=f%
::
:: Find gateway, this is the first occurrence after 0.0.0.0 in route output
::
FOR /F "TOKENS=3" %%G IN (
'ROUTE PRINT
^|FINDSTR "\<0.0.0.0\>"'
) DO (
SET Gateway=%%G
)
::
:: Filters Local IP Address from IpConfig command, needs delayed expansion
:: GetIp
::
FOR /F "TOKENS=2 DELIMS=:" %%I IN (
'IPCONFIG
^|FIND "IP"
^|FINDSTR/V ":.*:"'
) DO (
SET TempLocalIp=!TempLocalIp!,%%I
)
::
:: Strip out all the spaces
::
SET TempLocalIp=%TempLocalIp: =%
::
:: Strip first comma, this is a bit lame to me, see GetMac
::
SET LocalIp=%TempLocalIp:~1%
::
:: Print into Notepad
::
ECHO computer=%ComputerName% windows %WindowsVersion% %WindowsNumberOfBits%^
bit ip=%LocalIp% mac=%MacAddress%^
tcp=%Port% udp=%UdpPort% router= http://%Gateway%>%TMP%\eMuleData
NOTEPAD %TMP%\eMuleData
::
EXIT
::
:: License
::
Copyright (C) 2013-2015 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