Remote access control in the program

zhaozj2021-02-11  191

Remote access control of the program: xrbeck

Remote Access Service is a remote service provided by Windows NT, WIN2000 Server, which allows users to connect to a local computer network from the far end through dial-up connection, and once the connection is established, it is equivalent to the local In the LAN, you can use a wide variety of network functions for access. This article introduces you to this kind of technology that sounds very moved. :) First we need to configure the server-side RAS service, here as an example of 2K Server, the first installation modem, I believe that everyone should have no problem. After installing MODEM, select "Network and Dial-up Connections" in "Control Panel", New connection, select "Accept access to the connection", and add an account that allows you to log in, this article sets the username: XR password: XR, so that the server has established a "wait Access" connection, then Right click to select the property, select the TCP / IP protocol in the network because the author's LAN is through the proxy, static assignment reserved IP address 172.18. So select "Specify TCP / IP Address" from '172.18.1.27 "to" 172.18.1.28 "Allocate two IP addresses. This is because VLSM is 255.255.255.224, and 30 machines are retained in a LAN. Select behind several unallocated IP addresses. Open the management tool in the control panel, select route and remote access To select a local server, and "Configure and Enable Routing and Remote Access", you can view the port of the active or not. This is configured in the server side. Next to enter the key section: RAS connection is implemented at the remote. Also we need telephone lines and modem. After installation, we can use the RASAPI provided by the system to make dial-up connections. Take BCB5.0 as an example: give the export procedure as follows: 1. Connect the header RAS.H, Raserror.h and Library file Rasapi.lib This place should pay attention to a version conflict problem, so you need to set up Winver variables in the temporary settings. The specific code is as follows: #define oldver Winver # undef Winver # Define Winver 0x400

#include #include

#undef Winver # define Winver Oldver # undef OldVer After returing rasapi.lib, we can use the API function to make dialing.

2. Dial section: void __fastcall tform1 :: button1click (Tobject * sender) {// hrasconn = null; rasdialparams params; char buf [256]; MEMSET (BUF, 0, 256);

Params.dwsize = sizeof (rasdialparams);

LSTRCPY (params.szentryname, ""); lstrcpy (params.szphonenumber, "208"); lstrcpy (params.szusername, "xr"); lstrcpy (params.szpassword, "xr"); lstrcpy (params.szdomain, " ");

int RET = Rasdial (Null, Null, & Params, 0, & rasdialfunc, & Hrasconn); if (RET! = 0) {rasgetErRorstring (RET, BUF, 256); MemStatus-> Lines-> add (buf);}} where Rasdial For asynchronous access, 208 is the phone number of the server inside the company tested by the author. XR is the username and password of the login, because the test 2K Server is a normal member of the peer, no Domain, so set it to empty.

3. Tune function part: Similar to most of the Window programs, RAS also provides a callback function to process connections, so there are many cases, such as Winsock also provides an asynchronous way of window messages .void WinApi RasdialFunc (uint MSG, RasconnState RasconnState DWORD dwerror) {// char szrastring [256]; // buffer for storing the error string Memset (Szrasstring, 0,256); dword cb = sizeof (raspppip); dword ret;

if (dwError) // Error occurred {RasGetErrorString ((UINT) dwError, szRasString, 256); Form1-> memStatus-> Lines-> Add (szRasString); return;} switch (rasconnstate) {// Running States case RASCS_OpenPort: Form1-> MemStatus-> Lines-> Add ("Opening Port ..."); Break;

Case rascs_portopened: form1-> memstatus-> lines-> add ("port opened."); Break;

Case rascs_authenticated: form1-> memstatus-> lines-> add ("Authentication completion."); Break;

Case Rascs_Connected: Form1-> MemStatus-> Lines-> Add ("Connection Connected.");

Form1-> lpProjection = new RASPPPIP; Form1-> lpProjection-> dwSize = sizeof (RASPPPIP); if (RasGetProjectionInfo (Form1-> hrasconn, RASP_PppIp, Form1-> lpProjection, & cb) == ERROR_SUCCESS) {Form1-> memStatus-> LINES-> Add ("Server IP:" (Form1-> LPPROJECTION-> SZSERVERIPADDRESS); FORM1-> MemStatus-> Lines-> Add ("Local IP:" (ANSISTRING) (Form1-> LPPROJECTION) -> szipaddress);} Break; Case Rascs_disconnected: form1-> memstatus-> lines-> add ("disconnecting ..."); break;

DEFAULT: FORM1-> MEMSTATUS-> LINES-> Add ("unknown status"); Break;}} Processes various messages, where the connection section gets the connection allocated IP address and server address. Because it is a static assignment So, and the server side is in a subnet, you can use a wide variety of resources, such as using the WNET series function to get the situation in the LAN, or establish a socket after the Connect event, implementation, implementation Transfer. The author tests as follows: After unpluging the client's network cable, the author can establish the connection to other machines in the LAN after connecting the connection, and because it is in the subnet, it can be internetrated, and the subnet mask and gateway returned using the iPhelper function is Consistent.

This article introduces you what is RAS and how to program the implementation of RAS service, which is undoubtedly a convenient and powerful feature. I hope I can help you. I also welcome to continue discussions. QQ.33854303

Test Environment: Client BCB5.0 Win98. Server: WIN2000 Server Reference Book: Windows Network Programming Internet and TCP / IP Program Design C Builder Master

转载请注明原文地址:https://www.9cbs.com/read-5357.html

New Post(0)