腾讯云的Windows服务器防火墙,通过设置陷阱端口,屏蔽恶意访问的IP,将IP加入到腾讯云的安全组规则中,同时加入到服务器的防火墙中
unknown
2022-06-29 00ebde85aa3d586be2d2dfb755d01bf1b4b3025b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using TencentCloud.Cfw.V20190904;
using TencentCloud.Cfw.V20190904.Models;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Vpc.V20170312;
using TencentCloud.Vpc.V20170312.Models;
using TencentCloud.Ocr.V20181119;
using TencentCloud.Ocr.V20181119.Models;
using System;
using FirewallWindowsServer.Methods;
 
namespace Helpers
{
    public static class PublicApiHelpers
    {
 
 
        #region 腾讯API接口
 
        /// <summary>
        /// 发送“通用印刷体识别(高精度版)”请求(腾讯)
        /// </summary>
        /// <param name="SecretId">密钥参数SecretId</param>
        /// <param name="SecretKey">密钥参数SecretKey</param>
        /// <param name="Endpoint">请求URL</param>
        /// <param name="Region">地域参数,用来标识希望操作哪个地域的数据。</param>
        /// <param name="ImageUrl">
        /// 图片的 Url 地址。
        /// 要求图片经Base64编码后不超过 7M,分辨率建议600*800以上
        /// 支持PNG、JPG、JPEG、BMP格式。
        /// </param>
        /// <returns></returns>
        public static string SendGeneralAccurateOCRTC(string SecretId, string SecretKey, string Endpoint, string Region, string ImageUrl, string ImageBase64 = "")
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId = SecretId,
                    SecretKey = SecretKey
                };
 
                ClientProfile clientProfile = new ClientProfile();
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = (Endpoint);
                clientProfile.HttpProfile = httpProfile;
 
                OcrClient client = new OcrClient(cred, Region, clientProfile);
                GeneralAccurateOCRRequest req = new GeneralAccurateOCRRequest();
                if (!string.IsNullOrWhiteSpace(ImageUrl))
                {
                    req.ImageUrl = ImageUrl;
                }
                else
                {
                    req.ImageBase64 = ImageBase64;
                }
                GeneralAccurateOCRResponse resp = client.GeneralAccurateOCRSync(req);
                return AbstractModel.ToJsonString(resp);
            }
            catch (Exception e)
            {
                Command.PrintLog(e);
                return string.Empty;
            }
        }
 
        /// <summary>
        /// 添加云防火墙(需要购买才生效)
        /// </summary>
        /// <param name="SecretId">密钥参数SecretId</param>
        /// <param name="SecretKey">密钥参数SecretKey</param>
        /// <param name="IP">操作的IP</param>
        /// <param name="Endpoint">请求URL</param>
        /// <param name="Direction">操作类型,1入站,0出站</param>
        /// <param name="IocAction">操作属性,add,delete</param>
        /// <param name="StartTime">生效时间</param>
        /// <param name="EndTime">失效时间</param>
        public static void ModifyBlockIgnoreList(string SecretId, string SecretKey, string IP, string Endpoint = "cfw.tencentcloudapi.com", int Direction = 1, string IocAction = "add", string StartTime = "", string EndTime = "")
        {
 
            try
            {
                #region 默认值设置
                if (string.IsNullOrWhiteSpace(StartTime))
                {
                    StartTime = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss");
                }
                if (string.IsNullOrWhiteSpace(EndTime))
                {
                    EndTime = DateTime.Now.ToString("2099-MM-dd HH:mm:ss");
                }
                #endregion
 
 
                Credential cred = new Credential
                {
                    SecretId = SecretId,
                    SecretKey = SecretKey
                };
 
                ClientProfile clientProfile = new ClientProfile();
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = (Endpoint);
                clientProfile.HttpProfile = httpProfile;
 
                CfwClient client = new CfwClient(cred, "", clientProfile);
                ModifyBlockIgnoreListRequest req = new ModifyBlockIgnoreListRequest();
                req.RuleType = 1;
                IocListData iocListData1 = new IocListData();
                iocListData1.IP = IP;
                iocListData1.Direction = Direction;
                req.IOC = new IocListData[] { iocListData1 };
 
                req.IocAction = IocAction;
                req.StartTime = StartTime;
                req.EndTime = EndTime;
                ModifyBlockIgnoreListResponse resp = client.ModifyBlockIgnoreListSync(req);
                Console.WriteLine(AbstractModel.ToJsonString(resp));
            }
            catch (Exception e)
            {
                Command.PrintLog(e);
                Console.WriteLine(e.ToString());
            }
        }
 
        /// <summary>
        /// 添加安全组规则
        /// </summary>
        /// <param name="SecretId">密钥参数SecretId</param>
        /// <param name="SecretKey">密钥参数SecretKey</param>
        /// <param name="IP">操作的IP</param>
        /// <param name="Protocol">协议, 取值: TCP,UDP,ICMP,ICMPv6,ALL。</param>
        /// <param name="Port">端口(all, 离散port, range)。 说明:如果Protocol设置为ALL,则Port也需要设置为all。</param>
        /// <param name="Action">ACCEPT 或 DROP。</param>
        /// <param name="PolicyDescription">安全组规则描述</param>
        /// <param name="SecurityGroupId">安全组实例ID</param>
        /// <param name="Region">地域参数</param>
        /// <param name="Endpoint">接口请求域名</param>
        public static void DescribeSecurityGroupPolicies(string SecretId, string SecretKey, string IP, string Protocol, string Port,string Action,string PolicyDescription, string SecurityGroupId = "sg-ngm562yt", string Region = "ap-guangzhou", string Endpoint = "vpc.tencentcloudapi.com")
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId = SecretId,
                    SecretKey = SecretKey
                };
 
                ClientProfile clientProfile = new ClientProfile();
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = (Endpoint);
                clientProfile.HttpProfile = httpProfile;
 
                VpcClient client = new VpcClient(cred, Region, clientProfile);
                CreateSecurityGroupPoliciesRequest req = new CreateSecurityGroupPoliciesRequest();
                req.SecurityGroupId = SecurityGroupId;
                SecurityGroupPolicySet securityGroupPolicySet1 = new SecurityGroupPolicySet();
                SecurityGroupPolicy securityGroupPolicy1 = new SecurityGroupPolicy();
                securityGroupPolicy1.PolicyIndex = 0;
                securityGroupPolicy1.Protocol = Protocol;
                securityGroupPolicy1.Port = Port;
                securityGroupPolicy1.CidrBlock = IP;
                securityGroupPolicy1.Action = Action;
                securityGroupPolicy1.PolicyDescription = PolicyDescription;
                securityGroupPolicySet1.Ingress = new SecurityGroupPolicy[] { securityGroupPolicy1 };
 
                req.SecurityGroupPolicySet = securityGroupPolicySet1;
                CreateSecurityGroupPoliciesResponse resp = client.CreateSecurityGroupPoliciesSync(req);
                var res = AbstractModel.ToJsonString(resp);
                Command.PrintLog(res);
                Console.WriteLine(res);
            }
            catch (Exception e)
            {
                Command.PrintLog(e);
                Command.PrintLog(e.ToString());
            }
        }
        #endregion
 
        #region 百度API接口
 
        //private static string GetAccessTokenBD()
        //{
        //    var config = Tool.GetSystemConfig().BDApi;
 
        //    Dictionary<string, string> dic = new Dictionary<string, string>();
        //    dic.Add("grant_type", config.accessToken.grant_type);
        //    dic.Add("client_id", config.accessToken.client_id);
        //    dic.Add("client_secret", config.accessToken.client_secret);
        //    string paramStr = Tool.DicToUrlParam(dic);
 
        //    string res = Tool.HttpPost(config.accessToken.RequestUrl, paramStr);
 
        //    if (res.IndexOf("error") > -1)
        //    {
        //        //请求token错误,记录下错误情况
 
        //        Tool.PrintLog_Error("百度API Token验证获取失败", $"百度API Token验证获取失败,请求参数:{paramStr},请求地址:{config.accessToken.RequestUrl},返回结果:{res}");
        //        return string.Empty;
        //    }
 
        //    Hashtable hst = res.ToModel<Hashtable>();
 
        //    //记录到redis中
 
        //    return "";
        //}
 
 
        //public static string SendGeneralAccurateOCRBD() { }
 
        #endregion
    }
}