Help with network drive map - detect IP address and append

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stylishjm
Posts: 10
Joined: 10 Feb 2012 03:34

Help with network drive map - detect IP address and append

#1 Post by stylishjm » 17 Apr 2012 04:05

Hello,

Im trying to create a batch file which will map a network drive.
I'm planning to push this out via Eset Remote Administrator Console to over 50 computers in different sites.
As these obviously have different IP addresses, I need a way to detect the IP and append to the script.
All the network drives use this IP 10.x.x.13

For example:

IP at site is 10.124.116.13
IP at another site is 10.127.765.13

I need the script to replace the x's in 10.x.x.13 with the 124.116 etc etc.

Possible?

My script so far which doesn't work:

@ECHO OFF
NET USE Q: \\*_POS2\c$ /user:pos "pospospos" /persistent:yes

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help with network drive map - detect IP address and appe

#2 Post by aGerman » 17 Apr 2012 13:56

You could use a nested FOR /L loop to run across all possible IP adresses, ping them and if you get an answer then map it to the next free drive letter.
But there is an issue: How would you work around the fact that you have less than 26 free drive letters but more than 50 computers?

Regards
aGerman

stylishjm
Posts: 10
Joined: 10 Feb 2012 03:34

Re: Help with network drive map - detect IP address and appe

#3 Post by stylishjm » 18 Apr 2012 02:26

Apologies for not being too clear in the description.

Basically, there are 50+ servers for restaurants we deal with, each server is on site at the restaurant.
Each site has 3 - 6 POS tills running on Win 2000, and can manually map a drive from the server.

We need to map the drive to POS2 for each server, so there wont be any issues with drive letter allocations.
For each site, the server name remains the same, but the POS computer names are named using their store ID.

For example:
(Computer - Computer Name - IP)
Restaurant 1
Server - PCKDSBOH - 10.19.332.47
POS1 - 0119_POS1 - 10.19.332.12
POS2 - 0119_POS2 - 10.19.332.13
POS3 - 0119_POS3 - 10.19.332.14

Restaurant 2
Server - PCKDSBOH - 10.1.2.47
POS1 - UK232f_POS1 - 10.1.2.12
POS2 - UK232f_POS2 - 10.1.2.13
POS3 - UK232f_POS3 - 10.1.2.14
POS4 - UK232f_POS4 - 10.1.2.15

Restaurant 3
Server - PCKDSBOH - 10.99.67.47
POS1 - UK2009_POS1 - 10.99.67.12
POS2 - UK2009_POS2 - 10.99.67.13
POS3 - UK2009_POS3 - 10.99.67.14
POS4 - UK2009_POS4 - 10.99.67.15
POS5 - UK2009_POS5 - 10.99.67.16

So as you can see, they all contain a common element within the names, IP's and Computer Names.

I'm trying to create a script to push out, and auto run via ERAC, so the Drive Letter must be all the same ie. Q:\.
I know that that specific drive letter is free for all servers.
The script will ideally map the drive, then copy over a file from a folder on the C:\ drive to the C:\ drive on POS2 overwriting any files sharing the same name.
I've got most of it sorted, just need some help/ideas on getting the IP detected.

Thanks! :D

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help with network drive map - detect IP address and appe

#4 Post by aGerman » 18 Apr 2012 10:54

I'm not that familiar with remote stuff, sorry.
I assume you run the script on the server. In this case you need to determine the own IP address and extract the 2nd and 3rd octet. :?:

Code: Select all

@echo off

for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr /i "IPv*4*-Ad"') do (
  for /f "tokens=*" %%j in ("%%i") do (
    if not defined ipaddress1 set "ipaddress1=%%j"
    set "ipaddress2=%%j"
  )
)
echo first address in IPCONFIG: %ipaddress1%
echo last address in IPCONFIG:  %ipaddress2%
::::::::::::::::::::::::::::::::::::::::

ver|findstr /c:" 6.1." >nul && (set "v4=-4") || (set "v4=")
for /f "delims=[] tokens=2" %%i in ('ping -n 1 %v4% %computername%') do set "ipaddress3=%%i"
echo address via PING:          %ipaddress3%
::::::::::::::::::::::::::::::::::::::::

echo(
echo example how to extract the 2nd and 3rd octet
for /f "tokens=2,3 delims=." %%i in ("%ipaddress3%") do set "part=%%i.%%j"
echo %part%

pause


Regards
aGerman

stylishjm
Posts: 10
Joined: 10 Feb 2012 03:34

Re: Help with network drive map - detect IP address and appe

#5 Post by stylishjm » 19 Apr 2012 03:51

Excellent! That worked exactly as required!
Thank you! :D

Post Reply