わかりましたので、C# スクリプトに関数を追加して、IP アドレスをフェッチし、出力を変数の文字列として送信しました。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string URL = "http://localhost/test2.php";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["var1"] = formData["var1"] = string.Format("MachineName: {0}", System.Environment.MachineName);
formData["var2"] = stringGetPublicIpAddress();
formData["var3"] = "DGPASS";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string responsefromserver = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responsefromserver);
webClient.Dispose();
System.Threading.Thread.Sleep(5000);
}
private static string stringGetPublicIpAddress()
{
throw new NotImplementedException();
}
private string GetPublicIpAddress()
{
var request = (HttpWebRequest)WebRequest.Create("http://ifconfig.me");
request.UserAgent = "curl"; // this simulate curl linux command
string publicIPAddress;
request.Method = "GET";
using (WebResponse response = request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
publicIPAddress = reader.ReadToEnd();
}
}
return publicIPAddress.Replace("\n", "");
}
}
}
基本的に私はこの関数を作成しました
private static string stringGetPublicIpAddress()
変数として送信しています
formdata["var2"] = stringGetPublicIpAddress();
このエラーが発生しています
throw new NotImplementedException(); === NotImplementedException was unhandled