返回列表 发帖

[已解决]50元求修复代码,关于ip设置的问题

本帖最后由 beck1321 于 2013-1-8 16:15 编辑

具体报酬:50元软妹币
支付方式:支付宝
联系方式:QQ511156969
有效期限:2013年2月之前。
需求描述:如下
@echo off
echo 正在为您设置IP,请稍等......
set /A "a=%RANDOM%%%250+3
set /A "b=%RANDOM%%%250+3
set /A "c=%RANDOM%%%250+3
netsh interface ip set address name="本地连接" source=static addr=10.%a%.%b%.%c% mask=255.0.0.0 >nul
:start
set /A "num=%RANDOM%%%190+10"
ping 10.1.1.%num% -n 1 >nul
arp -a |find "10.1.1.%num%" &&goto start
netsh interface ip set address name="本地连接" source=static addr=10.1.1.%num% mask=255.255.255.0 gateway=10.1.1.250 gwmetric=0 | find "IP地址已在网络上使用" &&goto start
netsh interface ip set dns "本地连接" source=static addr=10.1.1.100 register=primary >nul
netsh interface ip add dns "本地连接" addr=8.8.8.8 >nul
netsh interface ip set wins name="本地连接" source=static addr=10.1.1.100 >nul
if %errorlevel% neq 0 goto startCOPY
这段代码 其中
set /A "num=%RANDOM%%%190+10"
ping 10.1.1.%num% -n 1 >nul
arp -a |find "10.1.1.%num%" &&goto startCOPY
这一段至关重要,是为了arp-a 得到 这个随机的num 的ip是否已有mac 即是否已在使用 如果有 则 继续 goto start
如果没有 则 继续下面的 ip配置工作


问题:
xp运行 这个代码 是没问题的,经过测试,能够发现已有ip 而重新start
但win7不行  ,我把>nul去掉 看状态 ping了以后 直接就配置下面的操作了。 给人感觉都没有执行arp -a   find这条命令 ,我在win7单独运行arp -a 这一行 ,是有显示的。但不知为何 整个代码运行时就不出现了。

(支付方式仅限支付宝)


==============
问题已解决,款已付。
感谢"无名"英雄  我猜你是论坛的高层哦!
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

我自己做了个测试 就是把1楼的代码 第6行去掉,(前提是我先手动设置了ip和子网掩码如10.22.22.22 255.0.0.0 )再运行的批处理  则3、4、5 肯定是不起作用的吧,因为我已经手动做好了这段批处理要做的事情。
我就发现 这么做就正常了

一旦把第6行代码 加入回去 又不行了
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

我是这么做测试的 比如10.1.1.10 有一台电脑肯定是开着的

我就 把代码改为
set /A "num=%RANDOM%%%1+10"

则代表 无论怎么随机 都是10

那势必就能体现出来对错了
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

echo 正在为您设置IP,请稍等......
set /A "a=%RANDOM%%%250+3
set /A "b=%RANDOM%%%250+3
set /A "c=%RANDOM%%%250+3
netsh interface ip set address name="本地连接" source=static addr=10.%a%.%b%.%c% mask=255.0.0.0
:start
set /A "num=%RANDOM%%%190+10"
ping 10.1.1.%num% -n 1
rem arp -a |find "10.1.1.%num%" &&goto start
%systemroot%\system32\arp.exe -a | %systemroot%\system32\find.exe "10.1.1.%num%" &&goto start
netsh interface ip set address name="本地连接" source=static addr=10.1.1.%num% mask=255.255.255.0 gateway=10.1.1.250 gwmetric=0 | find "IP地址已在网络上使用" &&goto start
netsh interface ip set dns "本地连接" source=static addr=10.1.1.100 register=primary
netsh interface ip add dns "本地连接" addr=8.8.8.8
netsh interface ip set wins name="本地连接" source=static addr=10.1.1.100
if %errorlevel% neq 0 goto startCOPY
如果仍然有问题,请把执行过程贴出来看看那。

TOP

或者把那行改成这样:
%systemroot%\system32\arp.exe -a 2>&1 | %systemroot%\system32\find.exe "10.1.1.%num%" &&goto startCOPY

TOP

回复 4# BAT-VBS


    好的 我尝试一下
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

回复 5# BAT-VBS


    您发的两个 都不行 我个人觉得 不是在arp这一行命令 是在第6行的命令

我待会儿发下 xp下 和win7的 运行过程
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

win7下  不成功的(不管是BAT-VBS 给我修改的还是原来的都不行)
C:\>b
C:\>set /A "a=24975%131+20
C:\>set /A "b=17566%251+3
C:\>set /A "c=31688%251+3
C:\>netsh interface ip set address name="本地连接" source=static addr=10.105.250
.65 mask=255.0.0.0 gateway=10.3.3.254 gwmetric=0
C:\>set /A "num=1399%1+232"
C:\>ping 10.3.3.232 -n 2
正在 Ping 10.3.3.232 具有 32 字节的数据:
PING: 传输失败。General failure.
PING: 传输失败。General failure.
10.3.3.232 的 Ping 统计信息:
    数据包: 已发送 = 2,已接收 = 0,丢失 = 2 (100% 丢失),
C:\>rem arp -a |find "10.3.3.232" &&goto start
C:\>C:\Windows\system32\arp.exe -a   2>&1  | C:\Windows\system32\find.exe "10.3.
3.232"   && goto start
C:\>netsh interface ip set address name="本地连接" source=static addr=10.3.3.232
mask=255.255.255.0 gateway=10.3.3.254 gwmetric=0
C:\>netsh interface ip set dns "本地连接" source=static addr=10.3.3.10 register=
primary
终止批处理操作吗(Y/N)? y
C:\>COPY
======

C:\>rem arp -a |find "10.3.3.232" &&goto start

C:\>C:\Windows\system32\arp.exe -a   2>&1  | C:\Windows\system32\find.exe "10.3.
3.232"   && goto start

就是这一段 运行是运行了这一行的命令 但直接进行下面的操作了。在这批处理运行前后 我均arp -a 看了下 我做测是的232 的mac都在本机的mac地址表里
======
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

本帖最后由 beck1321 于 2013-1-5 17:53 编辑

xp下没有那么多提示  但 成功的显示了 已占用ip 的mac 然后 一直goto start,win7那个运行过程 是用的BAT-VBS 您的修改的,即使是没修改的 也是那个样子,所以不用担心修改错了的问题
C:\>a
正在为您设置IP地址,请稍等......
确定。
Pinging 10.3.3.254 with 32 bytes of data:
Request timed out.
Ping statistics for 10.3.3.254:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
  10.3.3.254            1c-17-d3-dc-c0-78     dynamic
Pinging 10.3.3.254 with 32 bytes of data:
Request timed out.
Ping statistics for 10.3.3.254:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
  10.3.3.254            1c-17-d3-dc-c0-78     dynamic
Pinging 10.3.3.254 with 32 bytes of data:
Request timed out.
Ping statistics for 10.3.3.254:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
  10.3.3.254            1c-17-d3-dc-c0-78     dynamic
Pinging 10.3.3.254 with 32 bytes of data:
Request timed out.
Ping statistics for 10.3.3.254:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
  10.3.3.254            1c-17-d3-dc-c0-78     dynamic
Pinging 10.3.3.254 with 32 bytes of data:
Control-C
^C终止批处理操作吗(Y/N)? y
C:\>COPY
这个 我拿的另一个ip试的 254  其实 232  还是254 这个也不用考虑在出错可能的范围内  因为都是我管理的设备 确定都是开着的 而且 批处理win7 xp也都改过尝试用过
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

ping 不通  不代表得不到mac


win7明明可以得到mac 却不执行  goto  start
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

试试这样能否正确调整到:start
setlocal enabledelayedexpansion
echo 正在为您设置IP,请稍等......
set /A "a=%RANDOM%%%250+3
set /A "b=%RANDOM%%%250+3
set /A "c=%RANDOM%%%250+3
netsh interface ip set address name="本地连接" source=static addr=10.%a%.%b%.%c% mask=255.0.0.0
:start
set /A "num=%RANDOM%%%190+10"
ping 10.1.1.%num% -n 1
rem arp -a |find "10.1.1.%num%" &&goto start
%systemroot%\system32\arp.exe -a | %systemroot%\system32\find.exe "10.1.1.%num%"
echo !errorlevel!
if !errorlevel! equ 0 (
    goto :start
)
netsh interface ip set address name="本地连接" source=static addr=10.1.1.%num% mask=255.255.255.0 gateway=10.1.1.250 gwmetric=0 | find "IP地址已在网络上使用" &&goto start
netsh interface ip set dns "本地连接" source=static addr=10.1.1.100 register=primary
netsh interface ip add dns "本地连接" addr=8.8.8.8
netsh interface ip set wins name="本地连接" source=static addr=10.1.1.100
if %errorlevel% neq 0 goto startCOPY

TOP

你的Win7是32位的还是64位的?

TOP

按照您的那个 还是不行捏 下面是运行过程
C:\>c
C:\>setlocal enabledelayedexpansion
C:\>echo 正在为您设置IP,请稍等......
正在为您设置IP,请稍等......
C:\>set /A "a=13621%250+3
C:\>set /A "b=30738%250+3
C:\>set /A "c=23544%250+3
C:\>netsh interface ip set address name="无线网络连接" source=static addr=192.12
4.241.47 mask=255.0.0.0
C:\>set /A "num=25602%1+1"
C:\>ping 192.168.2.1 -n 2
正在 Ping 192.168.2.1 具有 32 字节的数据:
PING: 传输失败。General failure.
PING: 传输失败。General failure.
192.168.2.1 的 Ping 统计信息:
    数据包: 已发送 = 2,已接收 = 0,丢失 = 2 (100% 丢失),
C:\>rem arp -a |find "192.168.2.1" &&goto start
C:\>C:\Windows\system32\arp.exe -a   | C:\Windows\system32\find.exe "192.168.2.1
"
C:\>echo !errorlevel!
1
C:\>if !errorlevel! EQU 0 (goto :start )
C:\>netsh interface ip set address name="无线网络连接" source=static addr=192.16
8.2.1 mask=255.255.255.0 gateway=192.168.2.250 gwmetric=0   | find "IP地址已在网
络上使用"   && goto start
C:\>netsh interface ip set dns "无线网络连接" source=static addr=192.168.2.100 r
egister=primary
C:\>netsh interface ip add dns "无线网络连接" addr=8.8.8.8
配置的 DNS 服务器不正确或不存在。
终止批处理操作吗(Y/N)? y
C:\>COPY
我的是win7  32位  当然 也希望能应用于64位
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

我想问个问题

&&goto start 是去本批处理中的start

那么 我想让find以后打开 一个程序 如system32里的cmd。exe  是如何做到呢。我想做个测试
收入分四种:狂劳不得,多劳少得,少劳多得,不劳狂得。还好,我是第二种!

TOP

setlocal enabledelayedexpansion
echo 正在为您设置IP,请稍等......
set /A "a=%RANDOM%%%250+3
set /A "b=%RANDOM%%%250+3
set /A "c=%RANDOM%%%250+3
netsh interface ip set address name="本地连接" source=static addr=10.%a%.%b%.%c% mask=255.0.0.0
:start
set /A "num=%RANDOM%%%190+10"
ping 10.1.1.%num% -n 1
rem arp -a |find "10.1.1.%num%" &&goto start
arp -a >test.log
%systemroot%\system32\arp.exe -a | %systemroot%\system32\find.exe "10.1.1.%num%"
echo !errorlevel!
if !errorlevel! equ 0 (
    goto :start
)
netsh interface ip set address name="本地连接" source=static addr=10.1.1.%num% mask=255.255.255.0 gateway=10.1.1.250 gwmetric=0 | find "IP地址已在网络上使用" &&goto start
netsh interface ip set dns "本地连接" source=static addr=10.1.1.100 register=primary
netsh interface ip add dns "本地连接" addr=8.8.8.8
netsh interface ip set wins name="本地连接" source=static addr=10.1.1.100
if %errorlevel% neq 0 goto startCOPY
find命令没有找到那个IP
把win7里面test.log压缩一下传上来看看
1

评分人数

    • beck1321: 很认真 期待能够成功技术 + 1

TOP

返回列表