Computing.Net > Forums > Programming > Batch: Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch: Help

Reply to Message Icon

Name: Matt (by Mattio)
Date: August 20, 2009 at 11:48:02 Pacific
OS: Linux Mint-xfce
CPU/Ram: 1.397 GHz / 958 MB
Product: Toshiba / Satellite m40
Subcategory: Batch
Tags: Batch file
Comment:

Ok guys, I'm gonna cry soon.
I've tried this for a long time. And i know theres gonna be an easy solution & it's gonna be so simple.. I just can't figure it out.

Right i'll try keep it simple.
I'm creating a fake hacking simulation game in batch.
I have a "connect" command and a "netstat" command.
I want the user to type connect first, so they connect to something. Then they will have to use the Netstat command to view IP's and ports.

But the user can completely skip the connect part and go straight into netstat and view the IP.
I want it so if they type Netstat, it displays some IP's
And ONLY when they connect. It displays those IP's but with an added IP (which will be the IP that they connected too)

so it simulates how to gain the IP of a website.
I know it's not real...No comments about it, it's just a game i'm creating.

My idea is, When someone does the command to connect to a website. It sets some variable. Then when they do the Netstat command, it checks to see if that variable has been set.
I tried this but i couldn't get it to work. Hope you guys have some ideas.

Sorry if it makes no sence, It's really hard to explain what i want.

***************************
Need BatchFile Help ?
Msg me :)
***************************



Sponsored Link
Ads by Google

Response Number 1
Name: viddywell
Date: August 20, 2009 at 13:53:46 Pacific
Reply:

In your connect routine add
set connectcheck=1


Then as the first portion of your netstat routine add
IF %connectcheck% NEQ 1 goto connecterror

Add a connecterror variable that says something like

:connecterror
Echo No current network connection - please check your network connection
GOTO Connect


A little hard to be sure this lines up with what you're doing without actually seeing the code, but this should hopefully get you where you're trying to get.


0

Response Number 2
Name: Matt (by Mattio)
Date: August 20, 2009 at 13:57:15 Pacific
Reply:

Thanks, i shall try this.
This is something i've never come across before so i shall try it.
Thanks for the help!

***************************
Need BatchFile Help ?
Msg me :)
***************************


0

Response Number 3
Name: Matt (by Mattio)
Date: August 21, 2009 at 10:58:59 Pacific
Reply:

Ok. so i have added that code. If i type Connect-www.fakeomail.com
It works, Then when i type Netstat It goes to NETSTAT and displays what i want it to display. If i run the batch file again, but this time NOT connect first. I type Netstat the program just quits.
My guess is that its checking the variable that hasn't been set yet. So it's checking basically..Nothing, I'm messing around with it currently, any help will be grateful.

BOLD = Important parts


:MISSION1START
echo ****************
echo * Hack-o-matic *
echo ****************
echo.
SET /p Command=Command:
IF %Command% == Connect Goto CONNECTERROR
IF %Command% == Netstat Goto NETSTAT
IF %Command% == Shutdown Goto SHUTDOWNERROR
IF %Command% == Connect-www.fakeomail.com Goto CONNECTED
Goto SYNTAXERROR

:CONNECTED
set connectcheck=1
CLS
echo Connection Established with Http://www.Fakeomail.com
Goto MISSION1START

:NETSTAT
IF %connectcheck% NEQ 1 goto NETSTAT2
CLS
echo.
echo Active Connections
echo.
echo Proto Local Address Foreign Address State
echo TCP 127.0.0.1:2830 127.0.0.1:2831 ESTABLISHED
echo TCP 127.0.0.1:2831 127.0.0.1:2830 ESTABLISHED
echo TCP 127.0.0.1:4848 127.0.0.1:4849 ESTABLISHED
echo TCP 127.0.0.1:4849 127.0.0.1:4848 ESTABLISHED
echo TCP 127.0.0.1:4851 127.0.0.1:4852 ESTABLISHED
echo TCP 127.0.0.1:4852 127.0.0.1:4851 ESTABLISHED
echo TCP 192.168.1.33:1436 64.12.152.132:80 ESTABLISHED
echo TCP 192.168.1.33:1553 194.242.197.144:80 CLOSE_WAIT
echo TCP 192.168.1.33:2766 67.54.189.103:1863 ESTABLISHED
Pause

:NETSTAT2
CLS
echo.
echo Active Connections
echo.
echo Proto Local Address Foreign Address State
echo TCP 127.0.0.1:2830 127.0.0.1:2831 ESTABLISHED
echo TCP 127.0.0.1:2831 127.0.0.1:2830 ESTABLISHED
echo TCP 127.0.0.1:4848 127.0.0.1:4849 ESTABLISHED
echo TCP 127.0.0.1:4849 127.0.0.1:4848 ESTABLISHED
echo TCP 127.0.0.1:4851 127.0.0.1:4852 ESTABLISHED
echo TCP 127.0.0.1:4852 127.0.0.1:4851 ESTABLISHED
echo TCP 192.168.1.33:1553 194.242.197.144:80 CLOSE_WAIT
echo TCP 192.168.1.33:2766 67.54.189.103:1863 ESTABLISHED
Pause
goto MISSION1START

:CONNECTERROR
CLS
echo.
echo Nothing to connect too!
Pause
Goto MISSION1START

***************************
Need BatchFile Help ?
Msg me :)
***************************


0

Response Number 4
Name: viddywell
Date: August 22, 2009 at 16:02:03 Pacific
Reply:

I think you're probably spot on with your guess, in that case - let's set the connectcheck variable before we do anything else.


:PRESET
Set connectcheck=0

:MISSION1START
echo ****************
echo * Hack-o-matic *
echo ****************
echo.
SET /p Command=Command:
IF %Command% == Connect Goto CONNECTERROR
IF %Command% == Netstat Goto NETSTAT
IF %Command% == Shutdown Goto SHUTDOWNERROR
IF %Command% == Connect-www.fakeomail.com Goto CONNECTED
Goto SYNTAXERROR

:CONNECTED
set connectcheck=1
CLS
echo Connection Established with Http://www.Fakeomail.com
Goto MISSION1START

:NETSTAT
IF %connectcheck% NEQ 1 goto NETSTAT2
CLS
echo.
echo Active Connections
echo.
echo Proto Local Address Foreign Address State
echo TCP 127.0.0.1:2830 127.0.0.1:2831 ESTABLISHED
echo TCP 127.0.0.1:2831 127.0.0.1:2830 ESTABLISHED
echo TCP 127.0.0.1:4848 127.0.0.1:4849 ESTABLISHED
echo TCP 127.0.0.1:4849 127.0.0.1:4848 ESTABLISHED
echo TCP 127.0.0.1:4851 127.0.0.1:4852 ESTABLISHED
echo TCP 127.0.0.1:4852 127.0.0.1:4851 ESTABLISHED
echo TCP 192.168.1.33:1436 64.12.152.132:80 ESTABLISHED
echo TCP 192.168.1.33:1553 194.242.197.144:80 CLOSE_WAIT
echo TCP 192.168.1.33:2766 67.54.189.103:1863 ESTABLISHED
Pause

:NETSTAT2
CLS
echo.
echo Active Connections
echo.
echo Proto Local Address Foreign Address State
echo TCP 127.0.0.1:2830 127.0.0.1:2831 ESTABLISHED
echo TCP 127.0.0.1:2831 127.0.0.1:2830 ESTABLISHED
echo TCP 127.0.0.1:4848 127.0.0.1:4849 ESTABLISHED
echo TCP 127.0.0.1:4849 127.0.0.1:4848 ESTABLISHED
echo TCP 127.0.0.1:4851 127.0.0.1:4852 ESTABLISHED
echo TCP 127.0.0.1:4852 127.0.0.1:4851 ESTABLISHED
echo TCP 192.168.1.33:1553 194.242.197.144:80 CLOSE_WAIT
echo TCP 192.168.1.33:2766 67.54.189.103:1863 ESTABLISHED
Pause
goto MISSION1START

:CONNECTERROR
CLS
echo.
echo Nothing to connect too!
Pause
Goto MISSION1START


0

Response Number 5
Name: Matt (by Mattio)
Date: August 22, 2009 at 16:07:57 Pacific
Reply:

That looks promising now!
I'll try it Tomorrow.
Thanks for that help m8 !

***************************
Need BatchFile Help ?
Msg me :)
***************************


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch: Help

XCOPY - Batch Help www.computing.net/answers/programming/xcopy-batch-help/10929.html

Batch help - FTP but code cycles? www.computing.net/answers/programming/batch-help-ftp-but-code-cycles/15651.html

Batch Help www.computing.net/answers/programming/batch-help/5335.html