更换IP来批量下载

针对单点的批量下载器,除了数据库厂家对客户的IP限制,还有不少学校用电子资源控制系统进行监控,想要在连续时间断内批量下载是容易暴露的.对于以时间来限制的方法,可认通过设置时间间隔来躲避.而对于同一IP的下载次数限制,那就需要通过更换IP的方式来躲避.
而更换IP的方式,当然也要做成自动的,不可能让用户再手动更新,那就达不到"自动化"了.
在win中,动态更改IP有不少方法,有的直接调用winapi(类Win32_NetworkAdapterConfigurat ion官方文档: http://msdn.microsoft.com/zh-cn/library/aa394217(v=vs.85).aspx ),不管是C++或是C#甚至是vbs脚本.也可以通过在cmd下执行netsh命令来修改(可以写成bat,供程序从外部调用).

通过在程序中调用WINAPI,可以方便获得返回的状态,编制更健壮的程序.

对于躲避监控,最好的办法是执行分布式批量下载.当然,最安全的做法是,在几十个学校中执行.数据库商家及学校,都无法防得了.大多知名的迅速"暴富"的商业公司就是利用这种方法来积累资源的.只是可惜,学校里头的防控只防学生,却不防大虫.真所谓"窃钩者诛,窃国者为诸侯".有人指责我非法采集超星的视频,可这些道貌岸然的人物,为何不指责超星掏掉CNKI?不才只是为了方便穷书生找资源的苦楚,面对商业公司,而对国家科研机构的重重壁垒,让些小虫有点活路不坏垄断大局.知识越来越容易共享,也越来越不会分享.不管是商还是官,还是官商勾结,穷书生从不是他们的服务对象.我没有用上百台机器分布采集, 也没有直接挂机到镜像下载,我只是想从那个高墙处挖个小水沟,供穷书生们啜食.我只提供了省掉个人点击之苦的CNKI批量下载器,而且也做了数量的限制,别的下载器都限内部使用,没有在互联网上散播,希望那些高尚的大人物,莫太指责我恶意践踏知识产权,不尊重作者的研究成果.我只是一只小虫,挖个小洞,给穷书生们解解渴,因为穷书生们不能公款吃喝,大鱼大肉.

附:
C#
using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Text.RegularExpressions;
using  System.Management;


namespace  IPProvider
{
class  WMIForIPSet
{
public  WMIForIPSet()
{

}
/// 
///  设置IP地址信息
/// 
/// 
/// 
/// 
/// 
public  static  void  SetIPAddress( string [] ip,  string [] submask,  string [] gatway,  string [] dns)
{
ManagementClass wmi
  =  new  ManagementClass( " Win32_NetworkAdapterConfiguration " );
ManagementObjectCollection moc
  =  wmi.GetInstances();
ManagementBaseObject inPar
  =  null ;
ManagementBaseObject outPar
  =  null ;
foreach  (ManagementObject mo  in  moc)
{
// 如果没有启用IP设置的网络设备则跳过
if  ( ! ( bool )mo[ " IPEnabled " ])
{
continue ;
}
// 设置IP地址和掩码

if  (ip  !=  null  &&  submask  !=  null )
{
inPar
  =  mo.GetMethodParameters( " EnableStatic " );
inPar[
" IPAddress " ]  =  ip;
inPar[
" SubnetMask " ]  =  submask;
outPar
  =  mo.InvokeMethod( " EnableStatic " , inPar,  null );
}

// 设置网关地址

if  (gatway  !=  null )
{
inPar
  =  mo.GetMethodParameters( " SetGateways " );
inPar[
" DefaultIPGateway " ]  =  gatway;
outPar
  =  mo.InvokeMethod( " SetGateways " , inPar,  null );
}

// 设置DNS地址

if  (dns  !=  null )
{
inPar
  =  mo.GetMethodParameters( " SetDNSServerSearchOrder " );
inPar[
" DNSServerSearchOrder " ]  =  dns;
outPar
  =  mo.InvokeMethod( " SetDNSServerSearchOrder " , inPar,  null );
}
}
}
/// 
///  开启DHCP
/// 
public  static  void  EnableDHCP()
{
ManagementClass wmi
  =  new  ManagementClass( " Win32_NetworkAdapterConfiguration " );
ManagementObjectCollection moc
  =  wmi.GetInstances();
foreach  (ManagementObject mo  in  moc)
{
// 如果没有启用IP设置的网络设备则跳过

if  ( ! ( bool )mo[ " IPEnabled " ])
continue ;

// 重置DNS为空

mo.InvokeMethod(
" SetDNSServerSearchOrder " ,  null );
// 开启DHCP

mo.InvokeMethod(
" EnableDHCP " ,  null );
}
}
/// 
///  判断IP地址的合法性
/// 
/// 
/// 
public  static  bool  IsIPAddress( string  ip)
{
string [] arr  =  ip.Split( ' . ' );
if  (arr.Length  !=  4 )
return  false ;

string  pattern  =  @" \d{1,3} " ;
for  ( int  i  =  0 ; i  <</span> arr.Length; i++)
{
string d = arr[i];
if (i == 0 && d == "0")
return false;
if (!Regex.IsMatch(d, pattern))
return false;

if (d != "0")
{
d
 = d.TrimStart('0');
if (d == "")
return false;

if (int.Parse(d) > 255)
return false;
}
}

return true;
}
/// 

/// 设置DNS

/// 

/// 

public static void SetDNS(string[] dns)
{
SetIPAddress(
null, null, null, dns);
}
/// 

/// 设置网关

/// 

/// 

public static void SetGetWay(string getway)
{
SetIPAddress(
null, null, new string[] { getway }, null);
}
/// 

/// 设置网关

/// 

/// 

public static void SetGetWay(string[] getway)
{
SetIPAddress(
null, null, getway, null);
}
/// 

/// 设置IP地址和掩码

/// 

/// 

/// 

public static void SetIPAddress(string ip, string submask)
{
SetIPAddress(
new string[] { ip }, new string[] { submask }, null, null);
}
/// 

/// 设置IP地址,掩码和网关

/// 

/// 

/// 

/// 

public static void SetIPAddress(string ip, string submask, string getway)
{
SetIPAddress(
new string[] { ip }, new string[] { submask }, new string[] { getway }, null);
}
}
}


vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where MACAddress='00:24:8c:xx:xx:xx'")
strIPAddress = Array("192.168.17.14")
strSubnetMask = Array("255.255.255.192")
strGateway = Array("192.168.17.254")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
          IPChan=1
    Else
        IPChan=0
    End If
  Exit For
Next
If IPChan = 1 Then
    WScript.Echo "The IP address has been changed to 192网段"
Else
    WScript.Echo "The IP address could not be changed."
End If

cmd下用netsh:
C:\>netsh
netsh>interface
netsh interface>ip
netsh interface ip>set address name="本地连接" source=dhcp
netsh interface ip>set address "本地连接" static 192.168.0.2 255.255.255.0 192.168.0.1 1


转载出处:http://blog.sina.com.cn/s/blog_67532f7c0101aive.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值