基于AutoIt3的Ping、网址转IP地址,以及hosts文件写入
#include <Constants.au3>
#include <GUIConstantsEx.au3> GUICreate("通讯测试-mjywxy.xin", 400, 280)
GUICtrlCreateLabel("开始ping xxx.xxx.xxx.xxx", 30, 20)
$okbutton = GUICtrlCreateButton("确定", 170, 200, 80, 40)
GUISetState(@SW_SHOW)
;Sleep(2000)
Sleep(200)
GUICtrlCreateLabel(myping("xxx.xxx.xxx.xxx"), 30, 40)
Sleep(200) GUICtrlCreateLabel("开始检测mjywxy.xin是否xxx.xxx.xxx.xxx", 30, 70)
Sleep(100)
;$run = Run(@ComSpec & ' /k ping mjywxy.xin', @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
;ProcessWaitClose($run)
;MsgBox(0,"",StdoutRead($run))
TCPStartup()
If TcpNameToIp("mjywxy.xin")=="xxx.xxx.xxx.xxx" Then
GUICtrlCreateLabel("mjywxy.xin 的IP地址 [ 是 ] " & TcpNameToIp("mjywxy.xin"), 30, 90)
Else
GUICtrlCreateLabel("mjywxy.xin [ 不是 ] xxx.xxx.xxx.xxx, 而是" & TcpNameToIp("mjywxy.xin"), 30, 90)
EndIf Sleep(100)
GUICtrlCreateLabel("开始写入hosts文件", 30, 120) ;GUICtrlCreateLabel(FileReadLine('C:\Windows\System32\drivers\etc\hosts', -1), 30, 240) If FileExists("C:\Windows\System32\drivers\etc\hosts") Then
; If FileExists("hosts") Then
GUICtrlCreateLabel("hosts文件已存在", 30, 140)
If FileReadLine('C:\Windows\System32\drivers\etc\hosts', -1) == "xxx.xxx.xxx.xxx mjywxy.xin" Then
GUICtrlCreateLabel("hosts文件已经有数据", 30, 160)
Else
FileWriteLine('C:\Windows\System32\drivers\etc\hosts','xxx.xxx.xxx.xxx mjywxy.xin')
Sleep(200)
GUICtrlCreateLabel("写入hosts文件完成", 30, 160)
EndIf
Else
GUICtrlCreateLabel("hosts文件不存在,开始新建并写入原生hosts文件", 30, 140)
$myfile = "C:\Windows\System32\drivers\etc\hosts"
; $myfile = "hosts"
; FileDelete($myfile)
FileWriteLine($myfile,"# Copyright (c) 1993-2009 Microsoft Corp.")
FileWriteLine($myfile, "#")
FileWriteLine($myfile, "# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.")
FileWriteLine($myfile, "#")
FileWriteLine($myfile, "# This file contains the mappings of IP addresses to host names. Each")
FileWriteLine($myfile, "# entry should be kept on an individual line. The IP address should")
FileWriteLine($myfile, "# be placed in the first column followed by the corresponding host name.")
FileWriteLine($myfile, "# The IP address and the host name should be separated by at least one")
FileWriteLine($myfile, "# space.")
FileWriteLine($myfile, "#")
FileWriteLine($myfile, "# Additionally, comments (such as these) may be inserted on individual")
FileWriteLine($myfile, "# lines or following the machine name denoted by a '#' symbol.")
FileWriteLine($myfile, "#")
FileWriteLine($myfile, "# For example:")
FileWriteLine($myfile, "#")
FileWriteLine($myfile, "# 102.54.94.97 rhino.acme.com # source server")
FileWriteLine($myfile, "# 38.25.63.10 x.acme.com # x client host")
FileWriteLine($myfile, "")
FileWriteLine($myfile, "# localhost name resolution is handled within DNS itself.")
FileWriteLine($myfile, "# 127.0.0.1 localhost")
FileWriteLine($myfile, "# ::1 localhost")
FileWriteLine($myfile, "xxx.xxx.xxx.xxx mjywxy.xin")
FileClose($myfile)
GUICtrlCreateLabel("写入hosts文件完成", 30, 160)
EndIf While 1
$msg = GUIGetMsg() Select
Case $msg = $okbutton
;MsgBox(0, "GUI 事件", "您按下了[确定]按钮!")
ExitLoop Case $msg = $GUI_EVENT_CLOSE
; MsgBox(0, "GUI 事件", "您选择了关闭!正在退出...")
ExitLoop
EndSelect
WEnd Func myping($str)
; Ping 网站,超时时间为 1000 毫秒.
Local $iPing = Ping($str, 1000) If $iPing Then
; MsgBox(4096, "", "Ping "& $str &" 收发时间间隔: " & $iPing & "毫秒.")
Return "Ping "& $str &" 收发时间间隔: " & $iPing & "毫秒."
Else
;MsgBox(4096, "", "发生了一个错误, @error 值为: " & @error)
;当函数执行失败时(返回 0)@error 包含数值的具体信息:
If @error == 1 Then
Return "目标主机离线"
ElseIf @error == 2 Then
Return "目标主机无法到达"
ElseIf @error == 3 Then
Return "目标错误"
ElseIf @error == 4 Then
Return "其他错误-连接超时"
Else
Return "连接超时"
EndIf
; 1 = 目标主机离线
; 2 = 目标主机无法到达
; 3 = 目标错误
; 4 = 其它错误
EndIf
EndFunc ;==>Example
xxx.xxx.xxx.xxx 表示mjywxy.xin对应 ip
基于AutoIt3的Ping、网址转IP地址,以及hosts文件写入的更多相关文章
- JAVA 获取指定网址的IP地址 实例
如今买票是一大难事,在高峰时段 打开12306网站,慢的像蜗牛,想到以前用修改hosts文件来登录Google(Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址 ...
- 如何查询端口号和网址的ip地址?
import socket print socket.gethostname()#主机名 hostname=socket.gethostname() #传递主机名 print socket.getho ...
- php虚拟主机配置( 输入网址 对应 ip地址)
1.启动http_vhost.conf文件 在httpd-conf中,#virtual hosts 去掉前面的井号 # Includeconf/extra/httpd_vhost.conf 2.配置h ...
- 局域网内ping [局域网内ip地址]命令详解
一.工作过程 主机A向主机B发送一个ICMP请求报文[类型字段为8,代码字段为0],若收到ICMP回复报 文[类型字段为0,代码字段为0]则说明主机B处于活动状态:若超时未收到回复,则可能是 因为(1 ...
- 域名ping不通,ip地址ping得通
原因:dns服务器过期,需要更换dns服务器地址
- Apache服务(基于IP地址,主机名,端口号)
安装Apache服务程序 需要注意apache服务程序的软件包名称叫做httpd,因此直接执行yum install apache则是错误的. [root@liuxuanke-hbza ~]# yum ...
- Apache的虚拟主机功能(基于IP地址、基于虚拟主机、基于端口)
1. 安装Apache服务程序(系统用户,1-199之间) 第一步:在虚拟机软件里选中光盘镜像: 第二步:将光盘设备挂载到/media/cdrom目录 输入:mkdir -p /media/cdrom ...
- 为什么可以Ping通IP地址,但Ping不通域名?
能否ping通IP地址,与能否解析域名是两回事不能ping通IP地址,说明对方禁止ICMP报文或对方没有开机等解析域名只是将域名翻译成IP地址,不论该IP地址是否能够正常访问 问题是ping域名的时候 ...
- tomcat正常启动,但IP不能访问web。ping IP地址,一直超时。 用ipconfig命令修复TCP/IP的配置信息
今天遇到一个好奇葩的问题 好吧是昨天遇到的一直没找到解决办法(`へ´) tomcat正常启动,但是通过IP不能访问web 用IP地址就是不行 (:′⌒`) 打不开 localhost就可以 ...
随机推荐
- MaxCompute 助力衣二三构建智能化运营工具
摘要:本文由衣二三CTO程异丁为大家讲解了如何基于MaxCompute构建智能化运营工具.衣二三作为亚洲最大的共享时装平台,MaxCompute是如何帮助它解决数据提取速度慢.数据口径差异等问题呢?程 ...
- SPSS操作:轻松实现1:1倾向性评分匹配(PSM)
SPSS操作:轻松实现1:1倾向性评分匹配(PSM) 谈起临床研究,如何设立一个靠谱的对照,有时候成为整个研究成败的关键.对照设立的一个非常重要的原则就是可比性,简单说就是对照组除了研究因素外,其他的 ...
- python流程控制和循环
变量的命名:可以由数字字母下换线组成 ,不能以数字开头,可以使用中文但是不推荐使用中文,不推荐前面使用_ __,不能使用系统的关键字,变量名严格区分大小写 逻辑运算优先级 or<and<n ...
- 聊聊jdk http的HeaderFilter
序 本文主要研究一下jdk http的HeaderFilter. FilterFactory java.net.http/jdk/internal/net/http/FilterFactory.jav ...
- PHPCMS快速建站系列之需要掌握的函数
路径:phpcms\libs\classes\model.class.php /** * 执行sql查询 * @param $where 查询条件[例`name`='$name'] * ...
- 【JZOJ4841】【NOIP2016提高A组集训第4场11.1】平衡的子集
题目描述 夏令营有N个人,每个人的力气为M(i).请大家从这N个人中选出若干人,如果这些人可以分成两组且两组力气之和完全相等,则称为一个合法的选法,问有多少种合法的选法? 数据范围 40%的数据满足: ...
- [mysql]MySQL Daemon failed to start 2016-08-14 21:27 1121人阅读 评论(18) 收藏
前两天我们发现发布好的网站不可以进行注册,登陆这些活动,但是访问页面是正常的.于是开始对问题进行排查,首先我们重启了jenkins,但是每次重启都有错误,于是我们只能重启服务器,重启服务器需要重新启动 ...
- docker的ubuntu镜像无ifconfig和ping命令
docker的ubuntu镜像无ifconfig和ping命令 或者 ubuntu系统中无ifconfig 和 ping 解决方案: 执行以下鸣冷: apt-get update apt-get in ...
- python-----堡垒机前戏paramiko模块及进阶
堡垒机前戏 开发堡垒机之前,先来学习Python的paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作 SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: i ...
- APICloud原生APP中ajax需要用api.ajax
报错截屏: APICloud原生APP中ajax请求需要用api.ajax(api对象的ajax方法来替代),否则会将引起请求失败. APICloud api.ajax