基于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就可以 ...
随机推荐
- log4j:ERROR Could not read configuration file [log4j.properties]
遇到这个错误,程序能够正常运行,log4j.properties也在classpath中,后来在网上查了资料,把下面这个语句去掉就好啦. PropertyConfigurator.configure( ...
- Spring → 04:Bean(1)
一.Bean概念 Spring Bean是被实例的,组装的及被Spring 容器管理的Java对象. Spring 容器会自动完成@bean对象的实例化. 创建应用对象之间的协作关系的行为称为:装配( ...
- install4j的使用
用java写好了桌面应用,怎么搞成 那种常见的 双击之后 next.next...安装完成的按照包呢?用install4j.这东西有多好用呢?看看这款xml编辑软件,就是用install4j封装的安装 ...
- JDBC操作数据库实例
jdbc操作数据库实例 1.jdbc创建数据库 1.1 前提条件 1.拥有创建和删除表的权限 2.数据库已经启动,且可用 1.2 jdbc创建数据库表的步骤: 导包:导入需要进行数据库编程的 JDBC ...
- 2019-7-22-WPF-如何判断两个-LinearGradientBrush-相等
title author date CreateTime categories WPF 如何判断两个 LinearGradientBrush 相等 lindexi 2019-07-22 21:26:2 ...
- Person Re-identification 系列论文笔记(八):SPReID
Human Semantic Parsing for Person Re-identification Kalayeh M M, Basaran E, Gokmen M, et al. Human S ...
- python之浮点型类型
浮点型:float 如3.14,2.88 class float(object): """ float(x) -> floating point number Co ...
- Java练习 SDUT-2401最大矩形面积
最大矩形面积 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 在一个矩形区域内有很多点,每个点的坐标都是整数.求一个矩形 ...
- Java练习 SDUT-1131_最大公约数与最小公倍数
C/C++训练1---最大公约数与最小公倍数 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入两个正整数,求它们的最 ...
- hdu 1077 (圆交)
Problem - 1077 我们可以知道,当这个单位圆可以覆盖到最多的点的时候,必定最少有两个点位于这个圆的圆周上,于是就有网上众多的O(N^3)的枚举两个在圆上的点的暴搜做法. 然而这题是可以用圆 ...