diff --git a/ip2country.module b/ip2country.module
index 175ac78..9a6c10e 100644
--- a/ip2country.module
+++ b/ip2country.module
@@ -130,21 +130,8 @@ function ip2country_user_login(&$edit, &$account) {
   $ip = ip_address();
   $country_code = ip2country_get_country($ip);
 
-  // Now check to see if this user has "administer ip2country" permission
-  // and if debug mode set.  If both are TRUE, use debug information
-  // instead of real information.
-  if (user_access('administer ip2country') &&
-      variable_get('ip2country_debug', FALSE)) {
-    $type = variable_get('ip2country_test_type', 0);
-    if ($type == 0) {  // Debug Country entered.
-      $country_code = variable_get('ip2country_test_country', 'US');
-    }
-    else {  // Debug IP entered.
-      $ip = variable_get('ip2country_test_ip_address', $ip);
-      $country_code = ip2country_get_country($ip);
-    }
-    drupal_set_message(t('Using DEBUG value for Country - @country', array('@country' => $country_code)));
-  }
+  // Use debug information if user has permission and debug mode is enabled.
+  $country_code = ip2country_debug_mode($ip, $country_code);
 
   // Finally, save country, if it has been determined.
   if ($country_code) {
@@ -224,6 +211,29 @@ function ip2country_get_count() {
 }
 
 
+/**
+ * Returns debug information if user has permission and debug mode is enabled.
+ */
+function ip2country_debug_mode($ip, $country_code) {
+  // If this user has "administer ip2country" permission and if debug mode set.
+  if (user_access('administer ip2country') &&
+    variable_get('ip2country_debug', FALSE)) {
+    $type = variable_get('ip2country_test_type', 0);
+    if ($type == 0) {  // Debug Country entered.
+      $country_code = variable_get('ip2country_test_country', 'US');
+    }
+    else {  // Debug IP entered.
+      $ip = variable_get('ip2country_test_ip_address', $ip);
+      $country_code = ip2country_get_country($ip);
+    }
+
+    drupal_set_message(t('Using DEBUG value for Country - @country', array('@country' => $country_code)));
+  }
+
+  return $country_code;
+}
+
+
 /******************************************************************************
  * Ubercart Integration                                                       *
  ******************************************************************************/
diff --git a/ip2country.rules.inc b/ip2country.rules.inc
new file mode 100644
index 0000000..e1e410c
--- /dev/null
+++ b/ip2country.rules.inc
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * @file
+ * Rules integration for IP 2 country.
+ *
+ * @addtogroup rules
+ * @{
+ */
+
+/**
+ * Implements hook_rules_condition_info().
+ */
+function ip2country_rules_condition_info() {
+  $conditions = array();
+
+  $conditions['ip2country_user_is_in_country'] = array(
+    'label' => t('User is in country'),
+    'parameter' => array(
+      'countries' => array(
+        'type' => 'list<text>',
+        'label' => t('Countries'),
+        'options list' => 'country_get_list',
+        'restriction' => 'input',
+      ),
+    ),
+    'group' => t('IP 2 country'),
+    'callbacks' => array(
+      'execute' => 'ip2country_user_is_in_country',
+      'help' => 'ip2country_condition_user_is_in_country_help',
+    ),
+  );
+
+  return $conditions;
+}
+
+/**
+ * Users country by IP address condition help callback.
+ */
+function ip2country_condition_user_is_in_country_help() {
+  return t('Whether the user is in the selected country(ies).');
+}
+
+/**
+ * Returns TRUE if the users country is found in $countries.
+ *
+ * @param array $countries
+ *   An associated array of countries.
+ */
+function ip2country_user_is_in_country($countries) {
+  // Determine the user's country based on IP address.
+  $ip = ip_address();
+  $country_code = ip2country_get_country($ip);
+
+  // Use debug information if user has permission and debug mode is enabled.
+  $country_code = ip2country_debug_mode($ip, $country_code);
+
+  return in_array($country_code, $countries);
+}
+
+/**
+ * @}
+ */
