Outside are beautiful sunny days, so I spent most of my time outside my house with a wide channel, and somewhere in the park with a netbook and 4g modem. This is undoubtedly better for my health, but, nevertheless, I still want to download large files, so I had to find options for ways to organize access to my home network from outside. I will note right away that my provider gives out to its users
dynamic white IPv4 addresses (fortunately, with the commissioning of IPv6, the need for such perversions will automatically disappear).
The tasks before me are:
- Access to all computers on the network
- Support all protocols
- Ease of use
A word about the structure of my home network:
Computers (Win 7 + Win XP) -> Router (ZyXEL Keenetic 4G (firmware v2.00)) -> L2TP VPN -> Internet.
Several options are available for organizing access of this kind:
')
- VPN by type LogMeIn Hamachi
- Services dynamic DNS + probros ports on the router
- Bicycle: transfer of external IP to the outside + port forwarding on the router
In the process of consideration, the first option was dropped almost immediately, since it is not free, and it also gives access only to devices in general to all those added to the network, which does not add convenience.
The second option was no longer after a longer review, during which some flaws appeared:
- Access to only one computer
- Access is provided not by an appeal to IP, but through a frame, which greatly reduces the possibilities of using
- It is possible to redirect only HTTP, which is not good
Only the third option remains, which means we will fence our solution for our tasks.
To do this, you need to: first, find out the current external IP, secondly, transfer it somewhere outside, and finally - transfer the packets through home NAT. If you can handle the last task with the tools that each router has, then it’s already more difficult to deal with the first two.
So, after some hesitation, it was decided to use PowerShell, which is a built-in tool in Windows 7/8, to create the script, it can be installed in XP or Vista.
To get the external address, the site
myip.ru was used , the output of which was understood by regexp:
$ipsite = (new-object net.webclient).DownloadString("http://myip.ru")
if ($ipsite -cmatch '(?s)([0-9]{1,3}?\.[0-9]{1,3}?\.[0-9]{1,3}?\.[0-9]{1,3}?)') {
$ip = $matches[1]
} else {
Write-Error "Cannot get ip!"; return
}
Now that we know our IP address, we need to transfer it to the outside. For this, after some deliberation, I decided to use Dropbox. But there is one problem with its use: I wanted to create an html file that contained links to the necessary resources of my home network, but Dropbox does not show html created from Russia (from Russian IP). After some searching, it turned out that he gave himself quite xhtml files, so all that was left was to override the template and add it to the script.
The final version of the script is presented by
reference .
To run the script automatically, the standard task scheduler is used, which runs the script every 10 minutes. The file should be saved in the Public folder or its subfolders.
In order to simplify access to this file, and not memorize a long link to it, I used bit.ly and created there a bitmark with a memorable address.