#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文件写入的更多相关文章

  1. JAVA 获取指定网址的IP地址 实例

    如今买票是一大难事,在高峰时段 打开12306网站,慢的像蜗牛,想到以前用修改hosts文件来登录Google(Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址 ...

  2. 如何查询端口号和网址的ip地址?

    import socket print socket.gethostname()#主机名 hostname=socket.gethostname() #传递主机名 print socket.getho ...

  3. php虚拟主机配置( 输入网址 对应 ip地址)

    1.启动http_vhost.conf文件 在httpd-conf中,#virtual hosts 去掉前面的井号 # Includeconf/extra/httpd_vhost.conf 2.配置h ...

  4. 局域网内ping [局域网内ip地址]命令详解

    一.工作过程 主机A向主机B发送一个ICMP请求报文[类型字段为8,代码字段为0],若收到ICMP回复报 文[类型字段为0,代码字段为0]则说明主机B处于活动状态:若超时未收到回复,则可能是 因为(1 ...

  5. 域名ping不通,ip地址ping得通

    原因:dns服务器过期,需要更换dns服务器地址

  6. Apache服务(基于IP地址,主机名,端口号)

    安装Apache服务程序 需要注意apache服务程序的软件包名称叫做httpd,因此直接执行yum install apache则是错误的. [root@liuxuanke-hbza ~]# yum ...

  7. Apache的虚拟主机功能(基于IP地址、基于虚拟主机、基于端口)

    1. 安装Apache服务程序(系统用户,1-199之间) 第一步:在虚拟机软件里选中光盘镜像: 第二步:将光盘设备挂载到/media/cdrom目录 输入:mkdir -p /media/cdrom ...

  8. 为什么可以Ping通IP地址,但Ping不通域名?

    能否ping通IP地址,与能否解析域名是两回事不能ping通IP地址,说明对方禁止ICMP报文或对方没有开机等解析域名只是将域名翻译成IP地址,不论该IP地址是否能够正常访问 问题是ping域名的时候 ...

  9. tomcat正常启动,但IP不能访问web。ping IP地址,一直超时。 用ipconfig命令修复TCP/IP的配置信息

    今天遇到一个好奇葩的问题  好吧是昨天遇到的一直没找到解决办法(`へ´) tomcat正常启动,但是通过IP不能访问web 用IP地址就是不行  (:′⌒`)  打不开 localhost就可以    ...

随机推荐

  1. Laravel 虚拟开发环境 Homestead

    简介 Laravel 致力于让你在 PHP 开发过程中更加轻松愉快,这其中也包括本地开发环境的搭建. Vagrant 提供了一种简单.优雅的方式来管理和配置虚拟机. Laravel Homestead ...

  2. li设置多选和取消选择的样式、输入数据类型判断

    li设置多选和取消选择的样式: $('li').click(function(){ if($(this).hasClass('active')) {$(this).removeClass('activ ...

  3. IntelliJ Idea 复制粘贴的问题

    分析 尝试从外部复制内容向Idea工作空间内粘贴文件时,有一定的几率会发生复制粘贴失败的问题:复制了新的内容,粘贴的却还是早些时候复制的旧的内容. 我使用的IDEA是最新版(2016.1.3),操作系 ...

  4. jQuery迷你帮助查找功能

    在线演示 本地下载

  5. linux的简单操作

    查看当前用户who am i 创建用户:sudo adduser lilei然后输入密码 查看用户:ls /home 用新用户登陆:su -l lilei 查看所属用户组:groups 用户名 新建文 ...

  6. 2018-11-30-WPF-解决-ListView-的滚动条不显示

    title author date CreateTime categories WPF 解决 ListView 的滚动条不显示 lindexi 2018-11-30 19:24:57 +0800 20 ...

  7. 使用php实现单点登录实例详解

    1.首先准备两个虚拟域名 127.0.0.1 www.openpoor.com 127.0.0.1 www.myspace.com 2.在openpoor的根目录下创建以下文件 index.php文件 ...

  8. HTML之HTML标签

    前端的三把利器:                      (1)HTML就像一个赤裸裸的人                      (2)css就好比一件衣服                   ...

  9. 【C++】反向迭代器(rbegin,rend)(转载)

    转自:http://blog.csdn.net/kjing/article/details/6936325 rbegin和rend,很有用! C++ primer (中文版第四版)第273页 9.3. ...

  10. iOS之友盟错误统计解决

    http://www.cocoachina.com/ios/20150720/12627.html http://lieyunye.github.io/blog/2013/09/10/how-to-a ...