Internet Café Anti-black ARP defense double binding batch of articles

Source: Internet
Author: User
Tags bind exit
One: This batch processing has the flaw, sometimes cannot realize the true meaning double binds!

@echo off
:: Reading native MAC address
If exist Ipconfig.txt del Ipconfig.txt
Ipconfig/all >ipconfig.txt
If exist Phyaddr.txt del Phyaddr.txt
Find "Physical Address" ipconfig.txt >phyaddr.txt
for/f "skip=2 tokens=12"%%m in (phyaddr.txt) do set mac=%%m
:: Reading native IP address
If exist IPAddr.txt del IPaddr.txt
Find "IP address" ipconfig.txt >ipaddr.txt
for/f "skip=2 tokens=15"%%i in (IPAddr.txt) do set ip=%%i
:: Binding This machine IP address and MAC address
Arp-s%ip%%mac%
:: Reading gateway Address
If exist GateIP.txt del GateIP.txt
Find "Default Gateway" Ipconfig.txt >gateip.txt
for/f "skip=2 tokens=13"%%g in (GateIP.txt) do set gateip=%%g
:: Reading Gateway MAC address
If exist GateMac.txt del GateMac.txt
Arp-a%gateip% >gatemac.txt
for/f "Skip=3 tokens=2"%%h in (GateMac.txt) do set gatemac=%%h
:: Binding gateway Mac and IP
Arp-s%gateip%%gatemac%
ARP-S Gateway IP Gateway Mac
Exit

This batch to query the local ARP cache table, to see if there is a gateway IP and Mac, there can be successful

binding, but it's not going to tie up!!! But can be improved, to achieve the purpose of double binding, such as

Plus the Arp-s gateway IP Gateway mac One line is OK ...

Second, this also can not achieve the true meaning of the double binding, can only bind this machine IP and Mac (thanks to China DOS Alliance LXMXN provided)

@echo off
For/f "delims=: tokens=2"%%a in (' ipconfig/all^ find ' Physical address ') do set local_mac=%%a
For/f "delims=: tokens=2"%%a in (' ipconfig/all^ find ' IP addresses ') do set local_ip=%%a
For/f "delims=: tokens=2"%%a in (' ipconfig/all^ find "Default Gateway") do set gate_ip=%%a
fo*/*%%* in (' getmac/nh/s%local_ip% ') do set gate_mac=%%a
Arp-s%local_ip%%local_mac%
Arp-s%gate_ip%%gate_mac% (This place has problems, improvement ...) )


Tested, this batch can not bind gateway IP and Mac, can only bind this machine IP and Mac

Three, this is not very clear, I want to test the line, now know can bind this machine IP and Mac

(Thanks to China dos Alliance everest79)

@ECHO off
SETLOCAL enabledelayedexpansion
for/f "tokens=2 delims=[]="%%i in (' Nbtstat-a%computername% ') does call set local=!local!%%i
for/f "Tokens=3"%%i in (' netstat-r^ find ' 0.0.0.0 ') do set gm=%%i
for/f "tokens=1,2"%%i in (' Arp-a%gm%^ find/i/V "Inter") do set gate=%%i%%j
Arp-s%gate%
Arp-s%local%

ARP-S Gateway IP Gateway Mac
This batch can bind to the gateway IP and Mac, but there is still a flaw, to rely on the presence of ARP cache on this machine!
The improved method is to add a arp-s gateway IP and mac! at the end

Four, this is a brother found on the blog, the principle and the first one, just improved a little bit!

This p through Ping Gateway three times got the Gateway Mac in fact the above batches can be used to handle the gateway IP and Mac,
But if ARP spoofing occurs when the computer is turned on, the IP and Mac you are tying are wrong, and you can't surf the internet.

But this kind of situation is very few, sends over to try first!

@echo off

:::::::: Clear All ARP cache
Arp-d

(::::::::::: Reading local Connection Configuration
Ipconfig/all>ipconfig.txt

::::::: Read Intranet Gateway IP
for/f "Tokens=13"%%i in (' Find ' Default Gateway ' ipconfig.txt ') do set gatewayip=%%i

::::::::::::P ing three times intranet gateway
Ping%gatewayip%-N 3

:::::::: Read and gateway ARP cache
Arp-a find "%gatewayip%" >arp.txt

:::::::: Read Gateway Mac and bind
for/f "tokens=1,2"%%i in (' Find '%gatewayip% ' arp.txt ') do if%%i==%gatewayip% arp-s%%i

::::::::: Reading the Ip+mac of the local machine
for/f "Tokens=15"%%i in (' Find "IP address" ipconfig.txt ") do set ip=%%i
for/f "Tokens=12"%%i in (' Find "Physical Address" ipconfig.txt ") do set mac=%%i

::::::::::: Binding The Ip+mac of the machine
Arp-s%ip%%mac%

::::::::: Delete all temporary files
Del Ipconfig.txt
Del Arp.txt
Exit

The above p can be combined with the routing on the client's IP and Mac binding to achieve full anti-ARP, only the single binding under the Machine and gateway IP and Mac
Not much use, on the route above, because we use a different route, so this is not written!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.