嗨,我正在尝试制作一个bat文件来检查从不同服务器到一个特定服务器的可用性,以便检查它们之间是否存在防火墙,或者某种阻止连接的东西。问题是我不能使用第三方软件像portqry,nmap .所以我被困在这里,每一个小费都会有帮助的。
提前感谢XD,
发布于 2014-11-21 19:28:37
可以手动使用telnet。
echo.|telnet google.com 80但是telnet输出不能被处理,所以它对脚本没有用处。
这里有一个解决方案,它或多或少是欺骗(因为它创建了一个.exe文件),但不是下载。因为它将二进制数据包含在十六进制字符串中,所以它有点长,所以我不得不使用pastebin.com
另一个way.Using jscript.net/批处理混合(应该保存为bat),它还创建了一个小的exe文件。但是,设置套接字连接超时并不是那么简单的任务,因此如果端口不可用,它将等待太长时间:
@if (@X)==(@Y) @end /****** silent line that start jscript comment ******
@echo off
::::::::::::::::::::::::::::::::::::
::: compile the script ::::
::::::::::::::::::::::::::::::::::::
setlocal
::if exist portchk.exe goto :skip_compilation
set "frm=%SystemRoot%\Microsoft.NET\Framework\"
:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
if exist "%%v\jsc.exe" (
rem :: the javascript.net compiler
set "jsc=%%~dpsnfxv\jsc.exe"
goto :break_loop
)
)
echo jsc.exe not found && exit /b 0
:break_loop
%jsc% /nologo /out:"portchk.exe" "%~dpsfnx0"
::::::::::::::::::::::::::::::::::::
::: end of compilation ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation
:: download the file
::::just change the link and the file::::
portchk.exe google.com 80
portchk.exe google.com 666
exit /b 0
****** end of jscript comment ******/
import System;
import System.Net.Sockets;
import System.Timers;
var arguments:String[] = Environment.GetCommandLineArgs();
var remote_host=arguments[1];
var remote_port=arguments[2];
//var ipa= (IPAddress) Dns.GetHostAddresses(remote_host)[0];
var sock=new System.Net.Sockets.Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
try {
sock.Connect(remote_host, remote_port);
//sock.ConnectAsync(remote_host, remote_port);
timer_connection = new Timer();
Console.WriteLine("connected to something");
}catch (e) {
Console.WriteLine("Port is probably not available");
}https://stackoverflow.com/questions/27058173
复制相似问题