Blocking IP Address In Drupal 7 Via Code I want to know is there any function in DRUPAL 7 that I can send it an IP address as a parameter and it adds this ip to blacked_ips table ??

Indeed I have a rule that contains a Execution PHP action . In my action I want to add an IP to black list.
There isn't in core; system_block_ip_action() is about as close it you'll get, but that blocks the current IP.

Such a function would be trivial to implement though:

function block_ip($ip) {
  if (!(bool)db_query("SELECT 1 FROM {blocked_ips} WHERE ip = :ip", array(':ip' =&gt; $ip))-&gt;fetchField()) {
    db_insert('blocked_ips')-&gt;fields(array('ip' =&gt; $ip))-&gt;execute();    
  }
}