Script to find IP Third Octave in IP Address

Z

ZZMHume

Hello,

I my environment, I have a number of Office that are set up the same,
except they all have a Different IP Subnet...

i.e. 10.10.XXX.YYY

Where XXX is different in each Office.
Where YYY is a Different Computer in each Office.

Each Office has a SHARED Folder for keeping Data on the Primary System
(something like a server for storage).

My Goal is that have a Script of some sort that will do the following:

1. Run the Same Script on Each Machine, no matter where the system is
located
2. Find the IP Address of the system is was presently RAN on, not caring
if it was the Primary system or secondary...
3. Finding the Third Octave of the IP Address i.e. 10.10.XXX.1 ( grabing
the info of "XXX")
4. Next, taking the Info of "XXX" from Script previously ran and
inputting that info into a Mapping Command to MAP something as follows:

net use Z: \\10.10.XXX.1\Shared_Folder -persistant
 
D

David H. Lipman

From: "ZZMHume" <[email protected]>

| Hello,
|
| I my environment, I have a number of Office that are set up the same,
| except they all have a Different IP Subnet...
|
| i.e. 10.10.XXX.YYY
|
| Where XXX is different in each Office.
| Where YYY is a Different Computer in each Office.
|
| Each Office has a SHARED Folder for keeping Data on the Primary System
| (something like a server for storage).
|
| My Goal is that have a Script of some sort that will do the following:
|
| 1. Run the Same Script on Each Machine, no matter where the system is
| located
| 2. Find the IP Address of the system is was presently RAN on, not caring
| if it was the Primary system or secondary...
| 3. Finding the Third Octave of the IP Address i.e. 10.10.XXX.1 ( grabing
| the info of "XXX")
| 4. Next, taking the Info of "XXX" from Script previously ran and
| inputting that info into a Mapping Command to MAP something as follows:
|
| net use Z: \\10.10.XXX.1\Shared_Folder -persistant
|

Please ask in an appropriate Scripting news group.

NOTE: KiXtart has the macro @IPaddressX to provide IP info and the result can then be used
to extract the required data. KiXtart is the prefect scripting language for what you are
attempting.
 
A

Anteaus

Here's a roughout of how you would do this with AutoIt:

------------
$sharename = "myfiles"

$thisIP = userip("10.0.")

$octets = StringSplit($thisIP, ".")

$myServer= "10.0.0." & $octets[4]

$thisShare = "\\" & myServer & "\" & $sharename

DriveMapDel("Z:") ; Persistent share, so if you don't do this you cannot
re-map it.

sleep(500)

DriveMapAdd("Z:" , $thisShare, 1 ) ; (1 in flags field = persistent)

exit


func userIP($IPrange)
; Determines which of 4 LAN adapters has the local subnet:
; Messy code, could be improved, but hey it works!
$UserIP=""
$thisIP = @IPAddress1
If stringleft($thisIP,stringlen($IPrange)) = $IPrange then
$userIP=$thisIP
endif
$thisIP = @IPAddress2
If stringleft($thisIP,stringlen($IPrange)) = $IPrange then
$userIP=$thisIP
endif
$thisIP = @IPAddress3
If stringleft($thisIP,stringlen($IPrange)) = $IPrange then
$userIP=$thisIP
endif
$thisIP = @IPAddress4
If stringleft($thisIP,stringlen($IPrange)) = $IPrange then
$userIP=$thisIP
endif

Return $userIP
endfunc
-----------

Adapted from a similar script. Might contain a few tpyos so watch out.

Autoit compiler: http://www.autoitscript.com

:
 
P

Pegasus \(MVP\)

ZZMHume said:
Hello,

I my environment, I have a number of Office that are set up the same,
except they all have a Different IP Subnet...

i.e. 10.10.XXX.YYY

Where XXX is different in each Office.
Where YYY is a Different Computer in each Office.

Each Office has a SHARED Folder for keeping Data on the Primary System
(something like a server for storage).

My Goal is that have a Script of some sort that will do the following:

1. Run the Same Script on Each Machine, no matter where the system is
located
2. Find the IP Address of the system is was presently RAN on, not
caring if it was the Primary system or secondary...
3. Finding the Third Octave of the IP Address i.e. 10.10.XXX.1 (
grabing the info of "XXX")
4. Next, taking the Info of "XXX" from Script previously ran and
inputting that info into a Mapping Command to MAP something as follows:

net use Z: \\10.10.XXX.1\Shared_Folder -persistant

Try this four-line batch file, and watch out for line wrap:
@echo off
for /F "tokens=2 delims=:" %%a in ('ipconfig ^| find /i "IP Address"') do
set IP=%%a
for /F "tokens=3 delims=." %%a in ('echo %IP%') do set third=%%a
net use Z: \\10.10.%third%.1\Shared_Folder /persistent:yes

Watch out for the switch at the end, including the spelling: It is not
-persistant but
/persistent:yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top