Find Invalid IP Addresses
<p>Table: <code> logs</code></p>

<pre>
+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| log_id      | int     |
| ip          | varchar |
| status_code | int     |
+-------------+---------+
log_id is the unique key for this table.
Each row contains server access log information including IP address and HTTP status code.
</pre>

<p>Write a solution to find <strong>invalid IP addresses</strong>. An IPv4 address is invalid if it meets any of these conditions:</p>

<ul>
	<li>Contains numbers <strong>greater than</strong> <code>255</code> in any octet</li>
	<li>Has <strong>leading zeros</strong> in any octet (like <code>01.02.03.04</code>)</li>
	<li>Has <strong>less or more</strong> than <code>4</code> octets</li>
</ul>

<p>Return <em>the result table </em><em>ordered by</em> <code>invalid_count</code>,&nbsp;<code>ip</code>&nbsp;<em>in <strong>descending</strong> order respectively</em>.&nbsp;</p>

<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example:</strong></p>

<div class="example-block">
<p><strong>Input:</strong></p>

<p>logs table:</p>

<pre class="example-io">
+--------+---------------+-------------+
| log_id | ip            | status_code | 
+--------+---------------+-------------+
| 1      | 192.168.1.1   | 200         | 
| 2      | 256.1.2.3     | 404         | 
| 3      | 192.168.001.1 | 200         | 
| 4      | 192.168.1.1   | 200         | 
| 5      | 192.168.1     | 500         | 
| 6      | 256.1.2.3     | 404         | 
| 7      | 192.168.001.1 | 200         | 
+--------+---------------+-------------+
</pre>

<p><strong>Output:</strong></p>

<pre class="example-io">
+---------------+--------------+
| ip            | invalid_count|
+---------------+--------------+
| 256.1.2.3     | 2            |
| 192.168.001.1 | 2            |
| 192.168.1     | 1            |
+---------------+--------------+
</pre>

<p><strong>Explanation:</strong></p>

<ul>
	<li>256.1.2.3&nbsp;is invalid because 256 &gt; 255</li>
	<li>192.168.001.1&nbsp;is invalid because of leading zeros</li>
	<li>192.168.1&nbsp;is invalid because it has only 3 octets</li>
</ul>

<p>The output table is ordered by invalid_count, ip in descending order respectively.</p>
</div>

[]
['CREATE TABLE logs (\n    log_id INT,\n    ip VARCHAR(255),\n    status_code INT\n)\n', 'Truncate table logs', "insert into logs (log_id, ip, status_code) values ('1', '192.168.1.1', '200')", "insert into logs (log_id, ip, status_code) values ('2', '256.1.2.3', '404')", "insert into logs (log_id, ip, status_code) values ('3', '192.168.001.1', '200')", "insert into logs (log_id, ip, status_code) values ('4', '192.168.1.1', '200')", "insert into logs (log_id, ip, status_code) values ('5', '192.168.1', '500')", "insert into logs (log_id, ip, status_code) values ('6', '256.1.2.3', '404')", "insert into logs (log_id, ip, status_code) values ('7', '192.168.001.1', '200')"]
[{"value": "mysql", "text": "MySQL", "defaultCode": "# Write your MySQL query statement below\n"}, {"value": "mssql", "text": "MS SQL Server", "defaultCode": "/* Write your T-SQL query statement below */\n"}, {"value": "oraclesql", "text": "Oracle", "defaultCode": "/* Write your PL/SQL query statement below */\n"}, {"value": "pythondata", "text": "Pandas", "defaultCode": "import pandas as pd\n\ndef find_invalid_ips(logs: pd.DataFrame) -> pd.DataFrame:\n    "}, {"value": "postgresql", "text": "PostgreSQL", "defaultCode": "-- Write your PostgreSQL query statement below\n"}]
{"mysql": ["CREATE TABLE logs (\n    log_id INT,\n    ip VARCHAR(255),\n    status_code INT\n)\n"], "mssql": ["CREATE TABLE logs (\n    log_id INT,\n    ip VARCHAR(255),\n    status_code INT\n)\n"], "oraclesql": ["CREATE TABLE logs (\n    log_id NUMBER,\n    ip VARCHAR2(255),\n    status_code NUMBER\n)\n"], "database": true, "name": "find_invalid_ips", "postgresql": ["CREATE TABLE logs (\n    log_id INTEGER,\n    ip VARCHAR(255),           \n    status_code INTEGER        \n);"], "pythondata": ["logs = pd.DataFrame(columns=[\"log_id\", \"ip\", \"status_code\"]).astype({\"log_id\": \"Int64\", \"ip\": \"string\", \"status_code\": \"Int64\"})\n"], "database_schema": {"logs": {"log_id": "INT", "ip": "VARCHAR(255)", "status_code": "INT"}}}
{"mysql": ["MySQL", "<p><code>MySQL 8.0</code>.</p>"], "mssql": ["MS SQL Server", "<p><code>mssql server 2019</code>.</p>"], "oraclesql": ["Oracle", "<p><code>Oracle Sql 11.2</code>.</p>"], "pythondata": ["Pandas", "<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4</p>"], "postgresql": ["PostgreSQL", "<p>PostgreSQL 16</p>"]}
['Database']