copy ipv4 address to screen

August 16, 2010 at 18:35:57
Specs: Windows 7
Can i get a batch file to copy the ipv4 address for lan and wifi and have it shown on screen.

e.g. Your LAN IP Address is10.1.1.10
and your wireless IP Address is 10.1.1.14.

can i use ipconfig and specify which lines to grab?

Thanks in advance.


See More: copy ipv4 address to screen

Report •

#1
August 17, 2010 at 13:40:58
I currently am not on wireless, so I do not have a wireless address to test it on.

However, I'm hoping this will work for you:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET Number=1

FOR /f "tokens=14 delims= " %%a IN ('IPCONFIG ^| FINDSTR IPv4') DO (
	SET Var!Number!=%%a
	IF "!Number!"=="2" GOTO List
	SET /a Number +=1
)

:List

ECHO %Var1%
ECHO %Var2%
PAUSE


Report •

#2
August 17, 2010 at 14:12:19
this is very impressive. can you explain the for part to me quickly? only know a bit in batch. Also if i set up a %var3% will it work if there are 3 ipv4 address's found?

here is img link of your code in action: http://img718.imageshack.us/img718/...

i kind of like how nothing comes up if it can't find another one. could it specify ethernet ipv4 to correct lines?

search findstr ethernet as well as ipv4
then another line findstr wireless as well as ipv4

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET Number=1

FOR /f "tokens=14 delims= " %%a IN ('IPCONFIG ^| FINDSTR IPv4') DO (
SET Var!Number!=%%a
IF "!Number!"=="2" GOTO List
SET /a Number +=1
)

:List

echo Your LAN IP Address is: %Var1%
echo.
echo Your Wireless IP Address is: %Var2%
echo.
echo Your Hamachi IP Address is: %Var3%
echo.
pause


Report •

#3
August 17, 2010 at 14:50:07
Yes you can have it echo a third one, but you will also need to change:

IF "!Number!"=="2" GOTO List

To:

IF "!Number!"=="3" GOTO List

As well as adding

echo Your Hamachi IP Address is: %Var3%

----

What the for /f command does is loop through a text file, or in this case a command until it has completed.

FOR /f "tokens=14 delims= "

finds the 14th token with a [space] as the delimiter.

If you didn't understand that, it finds the 14th section with a [space] seperating them.

IN ('IPCONFIG ^| FINDSTR IPv4')

Finds the above in IPCONFIG, but the pipe ( | ) command specifies only the lines containing "IPv4".

DO (
SET Var!Number!=%%a
IF "!Number!"=="2" GOTO List
SET /a Number +=1
)

Sets var1 as whatever the for command finds, then increases the number by one, and sets var2 as the next string the for command finds. When the number reaches 2, it exits the loop and goes to list.

Hope I was able to clarify that for you.

----

Also, just out of curiosity, may I ask what is is you are doing that involves Hamachi?


Report •

Related Solutions

#4
August 17, 2010 at 21:41:08
Ah thanks matt123, i kinda missed the whole token part but i think i understand, thanks.

Oh, what I am doing was creating a loader for the game call of duty modern warfare 2. as instructions on how to lan, multiplayer etc where very hard to come by, so i tried to create a minimalistic loader with a batch file (as its all i can use).

For options 1 and 3 in the file below the host needs to know his ip and tell it to the client, so i will add this new code you gave me to the file.

Hamachi can enable the players to play an online lan if they so wish, as the game type spec ops is a two player campaign type.

Here is the code so far.

@echo off

title Call Of Duty Modern Warfare 2 - Multiplayer Loader

:menu
cls
echo This file is used to launch Call Of Duty Modern Warfare 2 - Multiplayer
echo without Steam for Online/Offline and LAN purposes.
echo.
echo.
echo Revision 4 - August 2010
echo.
echo.
pause

:choice
cls
echo Choose game type from the list below:
echo.
echo 1. Multiplayer (LAN or Online) - Host
echo 2. Multiplayer (LAN or Online) - Client
echo.
echo 3. Spec Ops (LAN or Online) - Host
echo 4. Spec Ops (LAN or Online) - Client
echo.
echo 5. Multiplayer Online - alterIWnet
echo.

set input=nothing
set /p input=Choice:
if %input%==1 goto one
if %input%==2 goto two
if %input%==3 goto three
if %input%==4 goto four
if %input%==5 goto five
goto choice


:one
cls
echo Type your IP address and ingame nickname below.
echo.
>alterIWnet.ini ECHO [Configuration]
>>alterIWnet.ini ECHO Server=
>>alterIWnet.ini ECHO WebHost=auto
>>alterIWnet.ini ECHO Nickname=
>>alterIWnet.ini ECHO [Dynamic]
>>alterIWnet.ini ECHO HackwarningShown=True
>>alterIWnet.ini ECHO ServerWarningShown=True

SET /p Server=Your IP address:
echo.
SET /p Nickname=Nickname:

SFK replace alterIWnet.ini /Server=/Server=%Server%/ -yes
SFK replace alterIWnet.ini /Nickname=/Nickname=%Nickname%/ -yes
cls
echo Welcome %nickname%.
echo.
echo The game will now start.
echo.
pause
start IWNetServer.exe
start iw4mp.exe
goto end

:two
cls
echo Type the host IP address and your ingame nickname below.
echo.
>alterIWnet.ini ECHO [Configuration]
>>alterIWnet.ini ECHO Server=
>>alterIWnet.ini ECHO WebHost=auto
>>alterIWnet.ini ECHO Nickname=
>>alterIWnet.ini ECHO [Dynamic]
>>alterIWnet.ini ECHO HackwarningShown=True
>>alterIWnet.ini ECHO ServerWarningShown=True

SET /p Server=Host IP address:
echo.
SET /p Nickname=Nickname:

SFK replace alterIWnet.ini /Server=/Server=%Server%/ -yes
SFK replace alterIWnet.ini /Nickname=/Nickname=%Nickname%/ -yes
cls
echo Welcome %nickname%.
echo.
echo The game will now start.
echo.
pause
start iw4mp.exe
goto end

:three
cls
echo Go to Spec Ops, Two Player Online, Select Mission, wait for client to connect.
echo Note that it may take a of minutes for client to connect.
echo.
echo You may get a alteriw notification about unofficial server or server down,
echo just press ok.
echo.
pause
start TeknoGods_MW2SP.exe
goto end

:four
cls
set /p variable=Host IP Address :
echo.
cls
echo Once in game press F12 to connect to host
echo Note that it may take a couple of minutes to connect to host.
echo.
echo You may get a alteriw notification about unofficial server or server down,
echo just press ok.
echo.
pause
start TeknoGods_MW2SP.exe --ip=%variable%
goto end

:five
cls
echo Type your ingame nickname below.
echo.
>alterIWnet.ini ECHO [Configuration]
>>alterIWnet.ini ECHO Server=server.alteriw.net
>>alterIWnet.ini ECHO WebHost=auto
>>alterIWnet.ini ECHO Nickname=
>>alterIWnet.ini ECHO [Dynamic]
>>alterIWnet.ini ECHO HackwarningShown=True
>>alterIWnet.ini ECHO ServerWarningShown=True

SET /p Nickname=Nickname:

SFK replace alterIWnet.ini /Nickname=/Nickname=%Nickname%/ -yes
cls
echo Welcome %nickname%.
echo.
echo The game will now start.
echo.
pause
start iw4mp.exe
goto end

:end
cls
echo This file was created to compile multiple multiplayer tools into the one file.
echo.
echo Credits go to:
echo.
echo Bob at alterIWNet for the IW Server Emulator.
echo Reaver at TeknoGods for the Multiplayer Spec Ops Tool.
echo.
echo AlterIWnet for making it all happen.
echo.
pause
exit


Report •

#5
August 17, 2010 at 23:50:21
When i try to have the first ip address show, auto copy itself to server input - var1, sfk doesnt like it and will not copy it to the server line in the alteriw file.

SET /p Server=Your IP address:%var1%
echo.
SET /p Nickname=Nickname:

SFK replace alterIWnet.ini /Server=/Server=%Server%/ -yes
SFK replace alterIWnet.ini /Nickname=/Nickname=%Nickname%/ -yes

i guess i could just have people type it out...


Report •

#6
August 18, 2010 at 17:36:25
Ahh yes, Modern warfare. I have it for PlayStation, but not for the computer. I was thinking about buying it though hehe.

I tested it out using SFK, The reason yours isn't working is because it is trying to replace "Server=" with "Server=Your IP Address is %Var1%". SFK doesn't work with spaces, as far as I know.

Here's how I did it:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET Number=1

FOR /f "tokens=14 delims= " %%a IN ('IPCONFIG ^| FINDSTR IPv4') DO (
	SET Var!Number!=%%a
	IF "!Number!"=="2" GOTO List
	SET /a Number +=1
)

SET Server=%Var1%
ECHO Your IP Address is %Var1%
ECHO.
ECHO What is your nickname?
SET /p Nickname=""

SFK replace alterIWnet.ini /Server=/Server=%Server%/ -yes>Nul
SFK replace alterIWnet.ini /Nickname=/Nickname=%Nickname%/ -yes>Nul
PAUSE

You need to remove the /p switch from the first one, and add an echo to echo the IP Address.

Good Luck.


Report •

#7
August 19, 2010 at 06:11:01
Please post finished code here, Id like to see that in action. And Matt, CODMW2 for the PC is awesome, that is if you have an awesome computer. :D

Report •

#8
August 19, 2010 at 07:51:47
That is finished, it works perfectly, you just have to integrate it into YOUR code.

Report •

#9
August 19, 2010 at 18:06:28
sweet thanks matt, will have to edit it in later today. also matt dont worry about buying mw2, its becoming obsolete as black ops comes out in november with dedicated server support as well as other features the mw2 lacked. but if you can just download a torrent of it. the reason for this script is mw2 doesnt support lan play, its like lan online with steam, quite silly...

Report •

#10
August 19, 2010 at 18:08:06
also here is a link for the modded community. quite alot of work these guys have done.

http://alteriw.net/


Report •

#11
August 19, 2010 at 18:29:45
You're welcome! Glad I was able to help.

Thanks for the Info on Call of Duty!


Report •

Ask Question