0

I just copied the below code from --> https://stackoverflow.com/a/5901991/4251338

@echo off
set ip_address_string="IPv4 Address"
rem Uncomment the following line when using older versions of Windows without IPv6 support (by removing "rem")
rem set ip_address_string="IP Address"
echo Network Connection Test
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do echo Your IP Address is: %%f

Its printing the couple of IP addresses which is on my machine:

 Your IP Address is:  xxx.xxx.xxx.100
 Your IP Address is:  xxx.xxx.xxx.174

But actually I want to connect / mount the following IP address as well as

 net use P: /del /yes
 net use P: \\xxx.xxx.xxx.xxx\d$\testing

 \\xxx.xxx.xxx.xxx\d$\testing (Which is available network IP)

Now the network should be like this: P:\Testing.

Could you someone help me on this one. Thanks in advance.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
ssr1012
  • 2,573
  • 1
  • 18
  • 30
  • I am not sure I understand. Do you want to map each IP on your own machine? – Gerhard Nov 12 '20 at 05:46
  • Sorry Its getting error. `System error 53 has occurred. The network path was not found.` – ssr1012 Nov 12 '20 at 05:56
  • We need to automate the requested batch script... `P:\testing` is the default mapping folder which is not user to do manually... users may be 'n' of users... Also the mapping function is required for other tools which is called in the perl script already written code. – ssr1012 Nov 12 '20 at 06:06
  • So is the network share for each user local to his/her own PC or is it an actual network share? – Gerhard Nov 12 '20 at 06:06
  • Yes. Just we need to map the folder (own folder) via IP address (own Machine) – ssr1012 Nov 12 '20 at 06:07
  • So what happened with `net use P: \\127.0.0.1\d$\testing` – Gerhard Nov 12 '20 at 06:09
  • sure it will connect But I had couple of IP addresses thats the problem... I need to automate which IP address is available... thats my question asked – ssr1012 Nov 12 '20 at 06:11
  • but `127.0.0.1` is the local address. Each PC should be able to map to local. – Gerhard Nov 12 '20 at 06:15
  • @SomeWittyUsername that is not related. OP wants to map each user's local folder to the active IP address to `P:` he is trying to determine which IP is active in order to know which one to use. – Gerhard Nov 12 '20 at 06:33
  • @SomeWittyUsername: Will try this one – ssr1012 Nov 12 '20 at 07:06
  • @ssr1012 you are not seeming to be clear here. I give you solutions, but you fail to respond in any decent manner so we can understand what you are trying to achieve here. The solution linked in the comment is not related to what you want to do, your problem, as you said, was to find the active IP, where the linked answer maps the first available drive without specifying a drive letter. – Gerhard Nov 12 '20 at 07:20
  • @Gerhard... Cool... I think you didn't see any of my answers in comment. I am responding and testing the solutions which you are all providing me for my questions. I need to come up for conclusion which one programmatically to connect the own machine into some drive letter. Please tell me now where am I failed now – ssr1012 Nov 12 '20 at 07:26
  • Well, as you can see, I am trying to help. If you are failing at anything I posted, please show me what did not work and I will try and assist to solve the problem. – Gerhard Nov 12 '20 at 07:33
  • `@echo off net use P: /del /yes net use P: \\localhost\c$\testing echo Network Connected` – ssr1012 Nov 12 '20 at 08:01

1 Answers1

1

I am really struggling to see what exactly is required and why using the local address cannot work:

net use P: \\127.0.0.1\d$\testing

or by local address name, which is always localhost

net use P: \\localhost\d$\testing

but if you really require the IPv4 address active to the internet:

@echo off
net use P: /del /yes
for /f "tokens=2 delims=:" %%f in ('ipconfig ^| findstr /c:"IPv4 Address"') do (
(ping -S %%f 8.8.8.8 -n 2 | findstr /i "TTL")>nul 2>&1 && net use P: "\\%%f\d$\testing"
)
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • 1
    Localhost only we can go with this since couple of IP we need to check which one is available and connecting.. Its tedious work lets make simple by `localhost` is the best way... – ssr1012 Nov 12 '20 at 08:02