概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
guiでhashをvirustotalに投げて、jsonを取得せよ。
写真
サンプルコード
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Windows.Forms;
using System.Drawing;
using LitJson;
using System.Net;
using System.Net.Http;
class form1: Form {
private TextBox textBox1;
private TextBox textBox2;
form1() {
Text = "virustotal";
ClientSize = new Size(300, 400);
Button btn1 = new Button();
btn1.Location = new Point(150, 150);
btn1.Text = "send";
btn1.Click += btn1_Click;
textBox1 = new TextBox();
textBox1.Location = new System.Drawing.Point(30, 30);
textBox1.Multiline = true;
textBox1.Size = new System.Drawing.Size(250, 50);
textBox1.TabIndex = 2;
textBox1.Text = "52d3df0ed60c46f336c131bf2ca454f73bafdc4b04dfa2aea80746f5ba9e6d1c";
textBox2 = new TextBox();
textBox2.Location = new System.Drawing.Point(30, 230);
textBox2.Multiline = true;
textBox2.Size = new System.Drawing.Size(250, 50);
textBox2.TabIndex = 2;
Controls.AddRange(new Control[] {
btn1,
textBox1,
textBox2
});
}
void btn1_Click(object sender, System.EventArgs e) {
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
string url = "https://www.virustotal.com/vtapi/v2/file/report?apikey=******&resource=" + textBox1.Text;
HttpClient client = new HttpClient();
string response = client.GetStringAsync(url).Result;
LitJson.JsonData json = LitJson.JsonMapper.ToObject(response);
Console.WriteLine("total: " + json["total"]);
Console.WriteLine("positive: " + json["positives"]);
textBox2.Text = json["positives"] + " / " + json["total"];
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
以上。