#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. R语言Switch语句

    R语言Switch语句 switch语句允许一个变量值的列表来平等进行测试.每个值被称为一个条件(情况),变量被接通检查每个条件(情况). 语法 在R语言中创建switch语句的基本语法是: 以下规则 ...

  2. Java 和 DynamoDB

    https://docs.aws.amazon.com/zh_cn/amazondynamodb/latest/developerguide/GettingStarted.Java.html 官方

  3. hdu3879 最大权闭合图

    若a,b 2点能够相连,那么可以得到ci的价值,也就是说a,b是得到c的前提条件,对于每一个点,又有耗费. 对于本题,先求出最多能够得到的利益有多少,最小割=未被 选的用户的收益之和 + 被选择的站点 ...

  4. hdu2018 dp

    /* 1~4直接取得: 然后后面的生牛的时候都是前一年的加上一定的数. 从第5年看,第五年出生的牛肯定要加上第四年出生的,然后由于第一个出生的牛开始生小牛,这和 最开始的牛生孩子是一样的,所以+dp[ ...

  5. jquery 即点即改

    //在html中建立表单. <table border=""> <th>编号</th> <th>用户名</th> < ...

  6. SharpDX初学者教程第5部分:着色三角形

    原文 http://www.johanfalk.eu/blog/sharpdx-beginners-tutorial-part-5-coloring-the-triangle 在第4部分中,我们创建了 ...

  7. ios程序员6级考试(答案和解释)

    http://blog.sunnyxx.com/2014/03/06/ios_exam_0_key/ 我是前言 上次发了个ios程序员6级考试题 ,还在不断补充中,开个帖子配套写答案和解释. 1. 下 ...

  8. AspNetPager 样式

    使用方法: 1.引入样式表. 将 想要使用的样式表加入到本页面<style type="text/css"></style>标记中,或者新建一个css文件如 ...

  9. How to use AutoMapper

    http://docs.automapper.org/en/stable/Getting-started.html IMappingExpression<TSource, TDestinatio ...

  10. 从零学React Native之01创建第一个程序

    本篇首发于简书 欢迎关注 上一篇文章是时候了解React Native了介绍了React Native.大家应该对React Native有个初步的认识. 接下来我们就可以初始化一个React Nat ...