Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I currently use a batch script to mount my network shares each morning:

NET USE * /DELETE /Y
NET USE Z: \\<IP>\<SHARE> <AUTHENTICATION> /persistent:no
...

Which is fine when I'm on the network, but doesn't work off-site. We have a domain which points to our public IP, and then port forwarding kicks in, so in theory, I can

NET USE * /DELETE /Y
NET USE Z: \\fqdn.com\<SHARE> <AUTHENTICATION> /persistent:no
...

Except that doesnt work in the batch script or windows UI.

I'm thinking there'd be a way to get the IP of fqdn.com (which is conveniently also stored at fqdn2.com/ip.txt) but there's well outside my experience of batching.

Any input much appreciated.

share|improve this question
    
Um, why not just change the end part to /persistent:yes? and not map your drives every day. –  Spencer5051 Jul 25 '13 at 1:31
    
You're allowing SMB in from the internet?! That's brave. –  afrazier Jul 29 '13 at 17:01
add comment

3 Answers

up vote 1 down vote accepted
+50

The task is a little bit easier by using PowerShell since you have the full power of the .Net framework at your disposal. There is a class called System.Net.WebClient that can be used to download a file and get its contents. You can use a PowerShell script similar to the one below to retrieve the contents of the ip.txt file and then execute your cmd.exe commands.

$fqdn = "fqdn domain name goes here"
$url  = "http://$fqdn/ip.txt"

$fqdnIp = (new-object System.Net.WebClient).DownloadString($url)

Write-Host -ForegroundColor Green "Retrieved contents of ${url}: $fqdnIp"

$cmd = "`"NET USE * /DELETE /Y`""
&cmd.exe /c $cmd

$cmd = "`"NET USE Z: \\$fqdnIp\<SHARE> <AUTHENTICATION> /persistent:no`""
&cmd.exe /c $cmd
share|improve this answer
    
PERFECT! Thank you for actually answering my question! –  LuckySpoon Jul 30 '13 at 8:50
add comment

Just because you can go to the website at fqdn.com, that does not give you access to your internal network or internal domain. Port 80 is the standard port for HTTP (websites) which is being forwarded from the public IP to your internal web server. However, with maybe a few other exceptions, that's all that's allowed through.

To access your internal network and resources, you need a virtual private network (VPN). A VPN is a secure (encrypted) connection from the Internet to your internal network. VPNing allows a computer outside your internal network to "feel" as if it is inside.

Once you have established a VPN connection, your batch script will work. You can access internal network drives and printers, and do anything you could do while in the office.

Microsoft offers a free VPN server with all versions of Windows Server and the client is built into all version of Windows. There are other VPN solutions out there as well, both hardware and software, both free and paid.

Talk to your Windows/network administrator, there may be a VPN already in place.

share|improve this answer
    
I think I may have not made my question clear - ports are all forwarded etc. My point is - if I can get the IP address that fqdn.com resolves to inside my batch script, all is fine. –  LuckySpoon Jul 24 '13 at 9:08
add comment

your scripts should work, except that you should check 4 things

  1. Is DNS working? try to verify it on your offsite machine by ping.
  2. try to disable WINS on your off-site client.
  3. Did you forward all the required ports ? try to put the server at DMZ host and see if that works.

    if the public ip does not change, then simple hard code it into your systems32\etc\hosts.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.