当前位置:网站首页>Three programming implementations to quickly determine whether the site is alive
Three programming implementations to quickly determine whether the site is alive
2022-07-19 10:25:00 【Dotnet cross platform】
Preface
How to know whether the external site is running ?
If you use a browser , Directly visit the corresponding site .
that , Use C# Programmatically , How to achieve it ?
GET request
First thought , Is the use of HttpClient Send to this site HTTP request , And check the return status :
var httpClient = new HttpClient();
var result = await httpClient.GetAsync("http://somesite.xxx");
Console.WriteLine(result.IsSuccessStatusCode);however ,GET The request will return the response body , It will consume certain bandwidth resources .
HEAD request
Ways to improve , It's using HEAD request , It does not return the response body :
var httpClient = new HttpClient();
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://somesite.xxx"),
Method = HttpMethod.Head
};
var result = await httpClient.SendAsync(request);
Console.WriteLine(result.IsSuccessStatusCode);however , There will also be some problems , For example, the site needs authentication , The above code will return false, Even if the site is running .
Ping
When using the command line , Can run ping Command and view the results :

C# You can also use Ping:
Ping ping = new Ping();
var hostName = new Uri("http://somesite.xxx").Host;
var result = await ping.SendPingAsync(hostName);
Console.WriteLine(result.Status == IPStatus.Success);It should be noted that , If the site turns on the firewall , It's forbidden ping Ordered ICMP Echo message , The above code will return false.
Conclusion
What other ways do you have ? Welcome to “My IO” Official account message discussion !
Add microsignals 【MyIO666】, Invite you to join the technical exchange group
边栏推荐
- 国产旗舰手机价格泡沫严重,二手比新机更划算,要不然就买iPhone
- 基于JSP的小说写作与创作网站
- HCIA OSPF
- Zhongke Panyun - Cyberspace Security packet capture topic b.pcap
- HCIA 复习作答 2022.7.6
- The R language uses the plot function in the native package (basic import package, graphics) to visualize the scatter plot
- Kirin Xin'an operating system derivative solution | host security reinforcement software, to achieve one click rapid reinforcement!
- Microsoft OneNote 教程,如何在 OneNote 中插入数学公式?
- HCIA 静态综合实验报告 7.10
- [Northeast Normal University] information sharing of postgraduate entrance examination and re examination
猜你喜欢

中科磐云——网络空间安全抓包题目 B.pcap

基于微信小程序的外卖点餐系统

HCIA 静态综合实验报告 7.10
![[Mori city] random talk on GIS data (IV) - coordinate system](/img/e8/a09dac9eef768de7baee4125fe52f9.png)
[Mori city] random talk on GIS data (IV) - coordinate system

Kirin Xin'an operating system derivative solution | host security reinforcement software, to achieve one click rapid reinforcement!

LVI-SAM:激光-IMU-相机紧耦合建图

C language structure to realize simple address book
![[Northeast Normal University] information sharing of postgraduate entrance examination and re examination](/img/a8/41e62a7a8d0a2e901e06c751c30291.jpg)
[Northeast Normal University] information sharing of postgraduate entrance examination and re examination

HCIA static basic experiment 7.8

Rasa 3. X learning series -rasa version 3.1.5 release
随机推荐
2022.07.13 暑假集训 个人排位赛(八)
[separate hyperimage classification platform] use those exciting models in deep learning to build an image classification platform
HCIA rip experiment 7.11
B. Accuratelee [double pointer] [substr function]
2022年全国最新消防设施操作员(中级消防设施操作员)模拟试题及答案
2022 Hunan secondary vocational group "Cyberspace Security" packet analysis infiltration Pacpng parsing (super detailed)
R language uses LM function to build linear regression model, and uses subset function to specify the subset of data set to build regression model (uses subset function to filter the data subset that
BEV空间内的特征级融合
Feature level fusion in Bev space
通过中序遍历和前序遍历,后续遍历来构建二叉树
Microsoft OneNote 教程,如何在 OneNote 中插入数学公式?
Rasa 3. X learning series -rasa version 3.1.5 release
十分钟从 PyTorch 转 MXNet(转)
R语言使用epiDisplay包的kap函数计算配对列联表的计算一致性的比例以及Kappa统计量的值、使用xtabs函数生成二维列联表
STM32F407 NVIC
C language structure to realize simple address book
Analysis of the "Cyberspace Security" competition of Hunan secondary vocational group in 2022 (super detailed)
idea展示服务端口--service
日期——贵州大学考研机试题目
ty_ Gr551x code framework