How to track my public IP address in a log file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I'd like to save my public IP address to a log file so I can use them to exclude my own visit to my websites in the stats collections.
At the moment I can see my actual public IP address--whatsmyip.org--but I believe that every time I off the modem, it changes.



I don't have a static public IP address, and I think there isn't a fixed range of IP that my ISP is giving me.



I'm running Linux Mint 17.3, is there any way that I've already a similar log file?
If not, can I track my future IPs and how?










share|improve this question




























    4















    I'd like to save my public IP address to a log file so I can use them to exclude my own visit to my websites in the stats collections.
    At the moment I can see my actual public IP address--whatsmyip.org--but I believe that every time I off the modem, it changes.



    I don't have a static public IP address, and I think there isn't a fixed range of IP that my ISP is giving me.



    I'm running Linux Mint 17.3, is there any way that I've already a similar log file?
    If not, can I track my future IPs and how?










    share|improve this question
























      4












      4








      4








      I'd like to save my public IP address to a log file so I can use them to exclude my own visit to my websites in the stats collections.
      At the moment I can see my actual public IP address--whatsmyip.org--but I believe that every time I off the modem, it changes.



      I don't have a static public IP address, and I think there isn't a fixed range of IP that my ISP is giving me.



      I'm running Linux Mint 17.3, is there any way that I've already a similar log file?
      If not, can I track my future IPs and how?










      share|improve this question














      I'd like to save my public IP address to a log file so I can use them to exclude my own visit to my websites in the stats collections.
      At the moment I can see my actual public IP address--whatsmyip.org--but I believe that every time I off the modem, it changes.



      I don't have a static public IP address, and I think there isn't a fixed range of IP that my ISP is giving me.



      I'm running Linux Mint 17.3, is there any way that I've already a similar log file?
      If not, can I track my future IPs and how?







      networking logs ip






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 20 '16 at 3:47









      overkill22overkill22

      21939




      21939




















          3 Answers
          3






          active

          oldest

          votes


















          3














          This one will give you your public IP, remove /ip part to see more info.



          $ curl ipinfo.io/ip





          share|improve this answer























          • It doesn't show my IP history, though. @cuongnv

            – overkill22
            Apr 21 '16 at 2:25











          • of course, it's not a full solution for you. But with it, you can write your own script, put that script in cron to make it get the IP and save into your log file.

            – cuongnv23
            Apr 21 '16 at 10:43


















          1














          You can try to use some dynamic dns services like noip.com
          Then You can access resources by dns name, which will changing according to Your ip.



          Generally, Your provider may NAT with pool of addresses. And every curl https://ipinfo.io/ip request will return a random address from this pool, depends on the settings of the NAT.



          It's better to use different methods to track visits to web-site. F.e. cookies.



          Here is a small python code to put in cron and collect addresses:



          #!/usr/bin/env python

          from datetime import datetime
          import os
          import requests

          LOG = '/tmp/ip.log'
          URL = 'https://ipinfo.io/ip'

          r = requests.get(URL)
          if r.status_code == 200:
          ip = r.content.decode('ascii').rstrip('n')
          last_ip = None
          if os.path.exists(LOG):
          f = open(LOG, 'r')
          last_ip = f.readlines()[-1].split()[-1]
          f.close()
          if ip != last_ip:
          f = open(LOG, 'a')
          f.write(" n".format(datetime.now(), ip))





          share|improve this answer

























          • Any practical example of how a dynamic-DNS service would allow OP to correlate a two week-old log entry from xxx.xxx.xxx.xxx with his IP address at that time?

            – techraf
            Apr 20 '16 at 8:32



















          0














          Add this line to your crontab file (crontab -e) to write the date and your public IPv4 address to a file called ip_public.txt, saved in your home directory, every day at 12:00 AM.



          0 0 * * * echo $(date +%Y-%m-%d) $(curl https://ipinfo.io/ip 2>/dev/null) >> ~/ip_public.txt 2>&1






          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f277703%2fhow-to-track-my-public-ip-address-in-a-log-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            This one will give you your public IP, remove /ip part to see more info.



            $ curl ipinfo.io/ip





            share|improve this answer























            • It doesn't show my IP history, though. @cuongnv

              – overkill22
              Apr 21 '16 at 2:25











            • of course, it's not a full solution for you. But with it, you can write your own script, put that script in cron to make it get the IP and save into your log file.

              – cuongnv23
              Apr 21 '16 at 10:43















            3














            This one will give you your public IP, remove /ip part to see more info.



            $ curl ipinfo.io/ip





            share|improve this answer























            • It doesn't show my IP history, though. @cuongnv

              – overkill22
              Apr 21 '16 at 2:25











            • of course, it's not a full solution for you. But with it, you can write your own script, put that script in cron to make it get the IP and save into your log file.

              – cuongnv23
              Apr 21 '16 at 10:43













            3












            3








            3







            This one will give you your public IP, remove /ip part to see more info.



            $ curl ipinfo.io/ip





            share|improve this answer













            This one will give you your public IP, remove /ip part to see more info.



            $ curl ipinfo.io/ip






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 20 '16 at 4:15









            cuongnv23cuongnv23

            745




            745












            • It doesn't show my IP history, though. @cuongnv

              – overkill22
              Apr 21 '16 at 2:25











            • of course, it's not a full solution for you. But with it, you can write your own script, put that script in cron to make it get the IP and save into your log file.

              – cuongnv23
              Apr 21 '16 at 10:43

















            • It doesn't show my IP history, though. @cuongnv

              – overkill22
              Apr 21 '16 at 2:25











            • of course, it's not a full solution for you. But with it, you can write your own script, put that script in cron to make it get the IP and save into your log file.

              – cuongnv23
              Apr 21 '16 at 10:43
















            It doesn't show my IP history, though. @cuongnv

            – overkill22
            Apr 21 '16 at 2:25





            It doesn't show my IP history, though. @cuongnv

            – overkill22
            Apr 21 '16 at 2:25













            of course, it's not a full solution for you. But with it, you can write your own script, put that script in cron to make it get the IP and save into your log file.

            – cuongnv23
            Apr 21 '16 at 10:43





            of course, it's not a full solution for you. But with it, you can write your own script, put that script in cron to make it get the IP and save into your log file.

            – cuongnv23
            Apr 21 '16 at 10:43













            1














            You can try to use some dynamic dns services like noip.com
            Then You can access resources by dns name, which will changing according to Your ip.



            Generally, Your provider may NAT with pool of addresses. And every curl https://ipinfo.io/ip request will return a random address from this pool, depends on the settings of the NAT.



            It's better to use different methods to track visits to web-site. F.e. cookies.



            Here is a small python code to put in cron and collect addresses:



            #!/usr/bin/env python

            from datetime import datetime
            import os
            import requests

            LOG = '/tmp/ip.log'
            URL = 'https://ipinfo.io/ip'

            r = requests.get(URL)
            if r.status_code == 200:
            ip = r.content.decode('ascii').rstrip('n')
            last_ip = None
            if os.path.exists(LOG):
            f = open(LOG, 'r')
            last_ip = f.readlines()[-1].split()[-1]
            f.close()
            if ip != last_ip:
            f = open(LOG, 'a')
            f.write(" n".format(datetime.now(), ip))





            share|improve this answer

























            • Any practical example of how a dynamic-DNS service would allow OP to correlate a two week-old log entry from xxx.xxx.xxx.xxx with his IP address at that time?

              – techraf
              Apr 20 '16 at 8:32
















            1














            You can try to use some dynamic dns services like noip.com
            Then You can access resources by dns name, which will changing according to Your ip.



            Generally, Your provider may NAT with pool of addresses. And every curl https://ipinfo.io/ip request will return a random address from this pool, depends on the settings of the NAT.



            It's better to use different methods to track visits to web-site. F.e. cookies.



            Here is a small python code to put in cron and collect addresses:



            #!/usr/bin/env python

            from datetime import datetime
            import os
            import requests

            LOG = '/tmp/ip.log'
            URL = 'https://ipinfo.io/ip'

            r = requests.get(URL)
            if r.status_code == 200:
            ip = r.content.decode('ascii').rstrip('n')
            last_ip = None
            if os.path.exists(LOG):
            f = open(LOG, 'r')
            last_ip = f.readlines()[-1].split()[-1]
            f.close()
            if ip != last_ip:
            f = open(LOG, 'a')
            f.write(" n".format(datetime.now(), ip))





            share|improve this answer

























            • Any practical example of how a dynamic-DNS service would allow OP to correlate a two week-old log entry from xxx.xxx.xxx.xxx with his IP address at that time?

              – techraf
              Apr 20 '16 at 8:32














            1












            1








            1







            You can try to use some dynamic dns services like noip.com
            Then You can access resources by dns name, which will changing according to Your ip.



            Generally, Your provider may NAT with pool of addresses. And every curl https://ipinfo.io/ip request will return a random address from this pool, depends on the settings of the NAT.



            It's better to use different methods to track visits to web-site. F.e. cookies.



            Here is a small python code to put in cron and collect addresses:



            #!/usr/bin/env python

            from datetime import datetime
            import os
            import requests

            LOG = '/tmp/ip.log'
            URL = 'https://ipinfo.io/ip'

            r = requests.get(URL)
            if r.status_code == 200:
            ip = r.content.decode('ascii').rstrip('n')
            last_ip = None
            if os.path.exists(LOG):
            f = open(LOG, 'r')
            last_ip = f.readlines()[-1].split()[-1]
            f.close()
            if ip != last_ip:
            f = open(LOG, 'a')
            f.write(" n".format(datetime.now(), ip))





            share|improve this answer















            You can try to use some dynamic dns services like noip.com
            Then You can access resources by dns name, which will changing according to Your ip.



            Generally, Your provider may NAT with pool of addresses. And every curl https://ipinfo.io/ip request will return a random address from this pool, depends on the settings of the NAT.



            It's better to use different methods to track visits to web-site. F.e. cookies.



            Here is a small python code to put in cron and collect addresses:



            #!/usr/bin/env python

            from datetime import datetime
            import os
            import requests

            LOG = '/tmp/ip.log'
            URL = 'https://ipinfo.io/ip'

            r = requests.get(URL)
            if r.status_code == 200:
            ip = r.content.decode('ascii').rstrip('n')
            last_ip = None
            if os.path.exists(LOG):
            f = open(LOG, 'r')
            last_ip = f.readlines()[-1].split()[-1]
            f.close()
            if ip != last_ip:
            f = open(LOG, 'a')
            f.write(" n".format(datetime.now(), ip))






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 2 at 8:51

























            answered Apr 20 '16 at 7:26









            Alex BezpalkoAlex Bezpalko

            112




            112












            • Any practical example of how a dynamic-DNS service would allow OP to correlate a two week-old log entry from xxx.xxx.xxx.xxx with his IP address at that time?

              – techraf
              Apr 20 '16 at 8:32


















            • Any practical example of how a dynamic-DNS service would allow OP to correlate a two week-old log entry from xxx.xxx.xxx.xxx with his IP address at that time?

              – techraf
              Apr 20 '16 at 8:32

















            Any practical example of how a dynamic-DNS service would allow OP to correlate a two week-old log entry from xxx.xxx.xxx.xxx with his IP address at that time?

            – techraf
            Apr 20 '16 at 8:32






            Any practical example of how a dynamic-DNS service would allow OP to correlate a two week-old log entry from xxx.xxx.xxx.xxx with his IP address at that time?

            – techraf
            Apr 20 '16 at 8:32












            0














            Add this line to your crontab file (crontab -e) to write the date and your public IPv4 address to a file called ip_public.txt, saved in your home directory, every day at 12:00 AM.



            0 0 * * * echo $(date +%Y-%m-%d) $(curl https://ipinfo.io/ip 2>/dev/null) >> ~/ip_public.txt 2>&1






            share|improve this answer



























              0














              Add this line to your crontab file (crontab -e) to write the date and your public IPv4 address to a file called ip_public.txt, saved in your home directory, every day at 12:00 AM.



              0 0 * * * echo $(date +%Y-%m-%d) $(curl https://ipinfo.io/ip 2>/dev/null) >> ~/ip_public.txt 2>&1






              share|improve this answer

























                0












                0








                0







                Add this line to your crontab file (crontab -e) to write the date and your public IPv4 address to a file called ip_public.txt, saved in your home directory, every day at 12:00 AM.



                0 0 * * * echo $(date +%Y-%m-%d) $(curl https://ipinfo.io/ip 2>/dev/null) >> ~/ip_public.txt 2>&1






                share|improve this answer













                Add this line to your crontab file (crontab -e) to write the date and your public IPv4 address to a file called ip_public.txt, saved in your home directory, every day at 12:00 AM.



                0 0 * * * echo $(date +%Y-%m-%d) $(curl https://ipinfo.io/ip 2>/dev/null) >> ~/ip_public.txt 2>&1







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 16 at 12:37









                NathanNathan

                15515




                15515



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f277703%2fhow-to-track-my-public-ip-address-in-a-log-file%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?