Remove records from mysql

Hi,

I have a voting poll database that received some really odd votes, the records show some very strange IPs.


4,546      Guest      455.513.414.406/24 /      April 2, 2012 @ 6:11 am
4,547      Guest      540.498.503.183/31 /      April 2, 2012 @ 6:11 am

A valid vote looks like this:


4,545      Guest      99.232.208.242 / ###.cable.rogers.com       April 2, 2012 @ 6:12 am

So i would like to run a sql query and search for all results that have these strange ip.

1) Can i run a sql command that will display the results of all strange IP addresses ?
2) Is there a REGEX sql command that that will search for invalid ip addresses ?
3) What would be the equiv. DELETE command to get rid of these queries.

Thaks,
ifredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

awking00Commented:
Can you provide a description of the table (i.e. column names and datatypes)?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ifredAuthor Commented:
1      pollip_id      int(10)
2      pollip_qid      varchar(10)
3      pollip_aid      varchar(10)
4      pollip_ip      varchar(100)
5      pollip_host      varchar(200)
6      pollip_timestamp      varchar(20
7      pollip_user      tinytext      utf8_general_ci
8      pollip_userid      int(10)

pollip_ip is the filed with the ip in question.
0
awking00Commented:
So, which if any or all of these values exist in the pollip_ip field?
4,546      Guest      455.513.414.406/24 /      April 2, 2012 @ 6:11 am
4,547      Guest      540.498.503.183/31 /      April 2, 2012 @ 6:11 am
4,545      Guest      99.232.208.242 / ###.cable.rogers.com       April 2, 2012 @ 6:12 am
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

ifredAuthor Commented:
455.513.414.406/24

and

 540.498.503.183/31

and

99.232.208.242
0
NorieData ProcessorCommented:
Perhaps a stupid question, but assuming ###.cable.rogers.com is in the host field, is there always a host when the IP is valid?
0
ifredAuthor Commented:
yes, i have 6000 records and i did not look at all of them but:

SELECT *
FROM  `wp_pollsip`
WHERE  `pollip_aid` LIKE  '6'
AND  `pollip_host` =  ' '
LIMIT 0 , 30

Does return me 6747 votes that i think are the ones I should null out.
0
NorieData ProcessorCommented:
So you mean you want to delete the records were the host field is empty?

Try this.

DELETE FROM `wp_pollsip` WHERE `poll_host` = '';

Or this.

DELETE FROM `wp_pollsip` WHERE `poll_host` is null;
0
ifredAuthor Commented:
Not really. Every record has an ip, and i am wondering if one would know a SQL statement i could use that will return all fields where wp_pollsip contains an invalid IP address.
Unfortunately I am not that good with Regex expressions.
0
NorieData ProcessorCommented:
So do you want to delete records with invalid IPs or validate the existing IPs?
0
ifredAuthor Commented:
i want to delete records with invalid IP addresses. Usually they have a number higher than 255 in at least one of the octets, those are REALLY invalid.
0
NorieData ProcessorCommented:
No problem, I was trying to do something with regexp but with no luck, so when you posted the table structure I just thought using the host field might work, wishful thinking I suppose.
0
ifredAuthor Commented:
While it could be one of the way to do this, it is probably not the best way to do it.
Let's see if anybody else can help and thanks anyway.
0
awking00Commented:
455.513.414.406/24
and
 540.498.503.183/31
and
99.232.208.242
So the first two are invalid why? Because they contain '/xx' at the end?
If that's the case, simply delete from wp_pollsip where instr(poll_ip,'/') >0
0
ifredAuthor Commented:
The first two ones are invalid because these are not valid IP numbers, IP numbers are up to 255 in any octet.
0
NorieData ProcessorCommented:
An IP can't have something like /24 at the end either.
0
Terry WoodsIT GuruCommented:
This picks up numbers greater than 255 or more than 3 digits:

select * from wp_pollsip where pollip_ip regexp '2[6-9][0-9]|25[6-9]|[3-9][0-9]{2}|[0-9]{4}'

(edit: fixed a bug)
0
ifredAuthor Commented:
I have fixed this by running a query that looked for "/" in the ip field, as i noticed it was recording this. All the fields with the "/" turned out to be invalid.
0
awking00Commented:
Does MySQL support a regex substring command?
0
ifredAuthor Commented:
There was not enough good answers, and my main point was still the main reason i solved my problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.