blocking IPv6 IP numbers

Discussion in 'IT & Internet' started by UKSBD, Sep 17, 2020.

  1. UKSBD

    UKSBD Not a real duck Staff Member

    10,230 2,009
    I block access to certain pages by IP using

    if (in_array ($_SERVER['REMOTE_ADDR'], $deny))

    It blocks the IPV4 numbers but doesn't appear to work on IPv6 IP numbers

    For example
    I've just upgraded my router and when doing a MY IP search it tells me my IP is now 2a00:23c6:ef08:d001:4919:7629:2d66:548

    If I put this in my array it doesn't block me like it should

    Using https://www.whatismyip.com/ I see I can convert it to the IPv4 IP and use this, but is there a way of blocking the IPv6 IP without me having to convert it 1st?
     
    Posted: Sep 17, 2020 By: UKSBD Member since: Dec 30, 2005
    #1
  2. gpietersz

    gpietersz UKBF Ace Full Member

    1,573 391
    I think depends whether the web server listens on IP4 or IP6 addresses. If your webserver listening to 0.0.0.0 (any IP4) then the remote address will be an IP4 too.

    What you are blocking and why? Lots of addresses or a few?
     
    Posted: Sep 17, 2020 By: gpietersz Member since: Sep 10, 2019
    #2
  3. UKSBD

    UKSBD Not a real duck Staff Member

    10,230 2,009
    The server must be listening on IP4 then, as blocking IPv4 numbers works but not IPv6 ones

    I use it to block cold callers
    The telephone numbers in my directory are on separate pages.
    If the same IP number is just going to random telephone number pages too often I assume it is just a cold caller collecting numbers so redirect them based on the IP number.
     
    Posted: Sep 17, 2020 By: UKSBD Member since: Dec 30, 2005
    #3
  4. gpietersz

    gpietersz UKBF Ace Full Member

    1,573 391
    I assume this is shared hosting so you cannot check the config directly? If your host manages your DNS look for AAAA records. If they are not there people cannot resolve your domain name to the IP6 address anyway.

    Maybe test page that just prints $_SERVER['REMOTE_ADDR'] and $_SERVER[''SERVER_ADDR'] to check.

    Is the list of addresses to deny manually updated or automatically?
     
    Posted: Sep 17, 2020 By: gpietersz Member since: Sep 10, 2019
    #4
  5. KM-Tiger

    KM-Tiger UKBF Legend Full Member - Verified Business

    10,029 2,695
    How did you know you were connecting using IPv6?
     
    Posted: Sep 18, 2020 By: KM-Tiger Member since: Aug 10, 2003
    #5
  6. UKSBD

    UKSBD Not a real duck Staff Member

    10,230 2,009
    I didn't.

    I used my IP to test it

    I went to get my IP the usual way just my searching on Google for MY IP but it returned the IPv6 version instead of the IPv4 version
    2a00:23c6:ef08:d001:44ce:c54b:f2f6:f7c9

    I then entered that in to my array thinking it would block me but it didn't, it only appears to work if I use an IPv4 number

    I've now found out different sites on different servers are set up differently

    If I go to https://www.uksmallbusinessdirectory.co.uk/ip-check.php it returns my IPv4 number

    if I go to https://www.uksbd.co.uk/ip-check.php it returns my IPv6 number.

    I assume this means I can only use IPv4 numbers on my directory site?


    On a side note:
    https://www.whatismyip.com/ must be pleased Google are only displaying the IPv6 number when searching for MY IP as they display both.

    Wonder how long it will be before Google do.
     
    Posted: Sep 18, 2020 By: UKSBD Member since: Dec 30, 2005
    #6
  7. UKSBD

    UKSBD Not a real duck Staff Member

    10,230 2,009
    It's not that many so I do it manually, gives me more ways of doing other things too (redirecting to different pages rather than just denying)

    I use Statcounter to get the IP's fortunately they return IPv4 numbers so it's not a problem.

    I only really discovered it because I wanted to use my IP as a test and found that searching for MY IP returned my IPv6 number.
     
    Posted: Sep 18, 2020 By: UKSBD Member since: Dec 30, 2005
    #7
  8. gpietersz

    gpietersz UKBF Ace Full Member

    1,573 391
    That is probably because there is an AAAA record for www.uksbd.co.uk but not for uksmallbusinessdirectory.co.uk

    So the DNS only returns an IP4 for the latter. You might be able to connect to the server running the latter over IP6 if it is listening on an IP6 address but that may not be a problem depending on what site (if any) http requests to the IP show.
     
    Posted: Sep 18, 2020 By: gpietersz Member since: Sep 10, 2019
    #8
  9. Darren_Ssc

    Darren_Ssc UKBF Ace Free Member

    1,366 444
    Posted: Sep 18, 2020 By: Darren_Ssc Member since: Mar 1, 2019
    #9