In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
I. demand analysis
As the previous home Internet is dialed to access the Internet, access is a public network ip, bind peanut shell dynamic domain name (account), and then through port mapping can be easily in any place with the network remote connection to the home computer H, recently peanut shell requires real name authentication, I go, so annoying, think about the principle, and existing resources, write one with python
Train of thought:
By dynamically obtaining the exit public network ip with python on the computer H (home) to be mapped and uploading it to the remote ftps (ftp + ssl) server at a fixed time of 10 minutes. When you want to connect to H, you can get the public network ip on the server (you can automatically pull it through the script, or you can look at it when you need to connect), and then connect to the H computer remotely.
2. Obtain the public network ip and upload the script automatically
1. Script getip.py
# coding:utf-8import urllib,urllib2from ftplib import FTP_TLSimport osimport reimport sysdef getIP (): url = "http://httpbin.org/ip" header = {" User-Agent ":" Mozilla/5.0 (Windows NT 6.1) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36 "} req = urllib2.Request (url=url, data=None, headers=header) response = urllib2.urlopen (req) html = urllib2.urlopen (req) content = html.read () myip = re.search ('\ d+\.\ d+\.\ d+\. Content) .group (0) return myipdef GETIP (event): myip = getIP () if myip: content.SetValue ("Local Public Network ip:% s"% myip) else: content.SetValue ("error") if _ _ name__ = = "_ main__": myip = getIP () filename= "% s.txt"% myip os.chdir ("d:\") if os.path. Isfile (filename): # do not execute sys.exit (5) else: ip_txt=open (filename) if the public network ip has not changed since the last time 'w') ip_txt.write (myip +'\ n') ip_txt.close () ftp = FTP_TLS () # # fill in your ftp user name and connection port ftp.connect ("Your ip or domain", port) ftp.login ('ftpuser') here Ftpuser') # # ftp username and password ftp.prot_p () ftp.cwd ("ip") # download# ftp.download ("1.txt", "1.txt") # ftp.retrlines ("LIST") # fnames = () # upload_file=unicode ('/ root/ip.txt', "utf8") upload_file=unicode (filename "utf8") # windows upload to ftp f = open (upload_file, 'rb') ftp.storbinary (' STOR% s'% os.path.basename (upload_file), f) f.close () ftp.quit
2. Add scheduled tasks
In the control panel of H computer, add tasks similar to the following in the scheduled tasks as shown in the figure:
Note: my H computer is xp, other windows system planning tasks are similar, Linux also supports, but need to pay attention to the file path modification in the script.
3. Get ip and upload with gui
1. Add the following code to the previous code:
App = wx.App () frame = wx.Frame (None, title= "get local egress public network ip", size= (300,180) panel = wx.Panel (frame) sBox = wx.BoxSizer () vBox = wx.BoxSizer (wx.VERTICAL) content = wx.TextCtrl (panel,style=wx.TE_MULTILINE | wx.TE_CENTER) btn1 = wx.Button (panel, label= "get") sBox.Add (btn1, proportion=1, flag=wx.EXPAND | wx.ALL Border=5) vBox.Add (sBox, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) vBox.Add (content, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) btn1.Bind (wx.EVT_BUTTON, GETIP) panel.SetSizer (vBox) frame.Show () app.MainLoop ()
2. The running effect is as shown in the figure:
3. The ip file obtained on the ftps server
Ftps is the environment of linux system vsftpd (for the construction of ftp and ftps, see ftp series http://dyc2005.blog.51cto.com/270872/1940990)
# pwd
/ data1/project/ip
# ls-alh
Total dosage 16K
Drwxr-xr-x 2 ftpuser nagioscacti 4.0K September 30th 07:17.
Drwxrwxr-x 5 ftpuser nagioscacti 4.0K September 28 18:24..
-rw-r--r-- 1 ftpuser nagioscacti 17 October 10 13:17 116.226.185.150.txt
-rw-r--r-- 1 ftpuser nagioscacti 17 October 10 13:22 180.168.251.164.txt
# cat 180.168.251.164.txt
180.168.251.164
The server has obtained the public network ip of the network where my H computer is located. If you want to know the public network ip elsewhere and connect to the H computer, just visit the ftps server to get the public network ip.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.