#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. thrift python安装

    http://thrift.apache.org/download/ tar -zxvf thrift-0.11.0.tar.gz cd thrift-0.11.0 ./configure --pre ...

  2. Directx11教程(61) tessellation学习(3)

    原文:Directx11教程(61) tessellation学习(3)       现在我们看看在不同tess factor的情况下,三角形是如何细分的?(这儿三条边和内部tess factor值是 ...

  3. c++之手写strcmp

    int strcmp(const char* str1, const char*str2){ assert(str1 != NULL&&str2 != NULL); while (*s ...

  4. 【Mysql的那些事】Django数据库配置

    1:安装与配置 1:pip install PyMySQL(或者直接使用Pycharm的setting,点击添加PyMySQL) 2:在Django的工程同名子目录的__init__.py文件中添加如 ...

  5. Java 并发工具箱之concurrent包

    概述 java.util.concurrent 包是专为 Java并发编程而设计的包.包下的所有类可以分为如下几大类: locks部分:显式锁(互斥锁和速写锁)相关: atomic部分:原子变量类相关 ...

  6. @loj - 2461@ 「2018 集训队互测 Day 1」完美的队列

    目录 @description@ @solution@ @part - 0@ @part - 1@ @accepted code@ @details@ @description@ 小 D 有 n 个 ...

  7. pytorch源码解析:Python层 pytorchmodule源码

    尝试使用了pytorch,相比其他深度学习框架,pytorch显得简洁易懂.花时间读了部分源码,主要结合简单例子带着问题阅读,不涉及源码中C拓展库的实现. 一个简单例子 实现单层softmax二分类, ...

  8. hdu 4629 Burning (扫描线)

    Problem - 4629 以前写过PSLG模拟的版本,今天写了一下扫描线做这题. 其实这题可以用set存线段来做,类似于判断直线交的做法.不过实现起来有点麻烦,于是我就直接暴力求交点了. 代码如下 ...

  9. SDUT-2122_数据结构实验之链表七:单链表中重复元素的删除

    数据结构实验之链表七:单链表中重复元素的删除 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 按照数据输入的相反顺序(逆 ...

  10. 实时计算轻松上手,阿里云DataWorks Stream Studio正式发布

    Stream Studio是DataWorks旗下重磅推出的全新子产品.已于2019年4月18日正式对外开放使用.Stream Studi是一站式流计算开发平台,基于阿里巴巴实时计算引擎Flink构建 ...