pengdc

arukas 樱花免费docker容器获取IP和端口

Posted on 2019-08-16 14:45 无名炮灰 阅读(...) 评论(...) 编辑 收藏

arukas 樱花免费docker容器,可以安装linux系统,但是每隔一段时间会重启,重启以后IP地址和映射到公网的端口都会变,获取IP和端口,我研究了很久终于找到了C#获取IP和端口的办法,用来搭建梯子很不错哦。

//Framework版本必须是4.5以上的
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;//必须要,不然无法访问https

string urlAddr = @"https://app.arukas.io/api/services/……appid……";

HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(urlAddr);
myReq.Method = "GET";
myReq.ContentType = "application/json";
string username = "……Token……";
string password = "……Secret……";
//注意这里的格式哦,为 "username:password"
string usernamePassword = username + ":" + password;
string code = Convert.ToBase64String(Encoding.ASCII.GetBytes(usernamePassword));
myReq.Headers.Add("Authorization", "Basic " + code);

HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
JObject MyData = JsonConvert.DeserializeObject<JObject>(content);
object resultStr = MyData["data"]["attributes"]["port-mappings"][0][0]["host"];
Regex reg = new Regex(@"\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}");
Match mc = reg.Match(resultStr.ToString());
string ipStr = mc.ToString().Replace('-', '.');
string oldPort = MyData["data"]["attributes"]["port-mappings"][0][0]["container-port"].ToString();
string newPort = MyData["data"]["attributes"]["port-mappings"][0][0]["service-port"].ToString();
HttpContext.Current.Response.Write(ipStr + ":" + newPort + "(" + oldPort + ")");
 

分类:

技术点:

相关文章:

  • 2021-09-04
  • 2021-09-10
  • 2022-12-23
  • 2021-12-03
  • 2021-08-29
  • 2022-12-23
  • 2021-07-26
猜你喜欢
  • 2021-10-23
  • 2021-10-19
  • 2021-10-16
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案