Mac Battery Status

The Mac can self-report some battery information, and Coconut Battery is pretty slick, too. But for someone handy with the command line, it turns out there’s a wealth of information about your battery and charger status.

Matthew.Wagner ~ $ system_profiler SPPowerDataType
Power:

    Battery Information:

      Model Information:
          Serial Number: D864196T1QQFT5YAS
          Manufacturer: SMP
          Device Name: bq20z451
          Pack Lot Code: 0
          PCB Lot Code: 0
          Firmware Version: 702
          Hardware Revision: 000a
          Cell Revision: 379
      Charge Information:
          Charge Remaining (mAh): 6106
          Fully Charged: No
          Charging: Yes
          Full Charge Capacity (mAh): 6271
      Health Information:
          Cycle Count: 112
          Condition: Normal
      Battery Installed: Yes
      Amperage (mA): 1074
      Voltage (mV): 12860

    System Power Settings:

      AC Power:
          System Sleep Timer (Minutes): 0
          Disk Sleep Timer (Minutes): 10
          Display Sleep Timer (Minutes): 62
          Wake on AC Change: No
          Wake on Clamshell Open: Yes
          Wake on LAN: Yes
          AutoPowerOff Delay: 14400
          AutoPowerOff Enabled: 1
          Current Power Source: Yes
          DarkWakeBackgroundTasks: 1
          Display Sleep Uses Dim: Yes
          PrioritizeNetworkReachabilityOverSleep: 0
          Standby Delay: 10800
          Standby Enabled: 1
      Battery Power:
          System Sleep Timer (Minutes): 1
          Disk Sleep Timer (Minutes): 10
          Display Sleep Timer (Minutes): 2
          Wake on AC Change: No
          Wake on Clamshell Open: Yes
          AutoPowerOff Delay: 14400
          AutoPowerOff Enabled: 1
          DarkWakeBackgroundTasks: 0
          Display Sleep Uses Dim: Yes
          Reduce Brightness: Yes
          Standby Delay: 10800
          Standby Enabled: 1

    Hardware Configuration:

      UPS Installed: No

    AC Charger Information:

      Connected: Yes
      ID: 0x0aa1
      Wattage (W): 85
      Family: 0x0085
      Serial Number: 0x00159fe3
      Charging: Yes

North Korea’s Internet Presence

The Boston Globe reports that North Korea is entirely offline.

Two quotes struck me. The first:

The country officially has 1,024 Internet protocol addresses, although the actual number may be somewhat higher. By comparison, the United States has billions of addresses.

That’s… Quite few. A lot of tiny hosting companies have more substantial netblocks.

CloudFlare, an Internet company based in San Francisco, confirmed Monday that North Korea’s Internet access was “toast.” A large number of connections had been withdrawn, “showing that the North Korean network has gone away,” Matthew Prince, CloudFlare’s founder, wrote in an email.

“Withdrawn” was interesting terminology to me, making me think that their routers had withdrawn their routes from the Internet / stopped advertising them. That could be caused by an attack, but the prefixes disappearing from the global routing table is slightly more extreme than their routers simply failing to pass traffic. So I wondered: what network(s) does North Korea have, and what happened to them? Let’s find out!

North Korea’s Address Space

This is a great page, listing the known networks assigned to North Korea. (It also contains an interesting scan of their IP space, albeit from a while ago.) According to that site, there are three netblocks:

  • 175.45.176.0/22 (the block of 1024 IPs the article mentions), owned by North Korea
  • 210.52.109.0/24 from China Unicom (not China Unicorn as my eyes read every time)
  • 77.94.35.0/24 from a satellite provider

The first is the official one that they control, and the other two are delegated from other carriers’ IP space.

175.45.176.0/22 is “toast”

To borrow the term from the CloudFlare quote, their main netblock is “toast.” Taking a look at various looking glasses, the network doesn’t exist in the global routing table:

  • Cogent’s looking glass: “% Network not in table”
  • HE: “None of the BGP4 routes match the display condition”
  • nLayer GTT “No route found.”

The other two networks are still in the routing table, but that’s unsurprising since they’re managed by other ISPs. North Korea’s main netblock has disappeared from the Internet routing tables entirely.

.kp is offline

The .kp TLD has two nameservers, and they’re both in the vanished 175.45.176.0/22 block:

;; QUESTION SECTION:
;kp.                IN  NS

;; AUTHORITY SECTION:
kp.         172800  IN  NS  ns2.kptc.kp.
kp.         172800  IN  NS  ns1.kptc.kp.

;; ADDITIONAL SECTION:
ns1.kptc.kp.        172800  IN  A   175.45.176.15
ns2.kptc.kp.        172800  IN  A   175.45.176.16

(As an aside, I had a hard time hosting my own DNS for a .com domain because I was supposed to have two nameservers on separate /24s. Here is a TLD that doesn’t meet that requirement.)

So, other than anything already cached, nothing in .kp can possibly resolve right now.

North Korean websites

As an aside, here is a list of every .kp domain I can find in existence:

  • airkoryo.com.kp (The website of state airline, Air Koryo)
  • friend.com.kp (The website of the Committee for Cultural Relations with Foreign Countries)
  • kcna.kp (The website of the Korean Central News Agency)
  • knic.com.kp
  • koredufund.org.kp
  • korelcfund.org.kp
  • korfilm.com.kp (The website of the Pyongyang Film Festival)
  • ksf.com.kp
  • naenara.com.kp (The official North Korean governmental portal, Naenara)
  • rodong.rep.kp (The website of the Rodong Sinmun newspaper)
  • vok.rep.kp (The website of shortwave station Voice of Korea)

Descriptions, where present, come from the .kp Wikipedia page. My list comes from Wikipedia and a private crawler. (They’re not linked because none of them could resolve right now.)

This site has another list.

Customizing TextMate Next- and Previous-Tab Keyboard Shortcuts

I was kind of surprised to find that TextMate (at least TextMate 2) doesn’t allow you to edit keyboard shortcuts. I found myself repeatedly trying to use the next- and previous-tab shortcuts I use in Chrome while in TextMate, which… didn’t work. A “good” user would probably learn the right shortcuts, but I wanted the software to change, not my brain.

I found most of the solution on Jason Seifer’s blog (thanks!). I never realized you can set application-specific keyboard shortcuts in OS X, and that’s exactly what I needed. Unfortunately, since his post (or maybe between TextMate and TextMate 2), the menu text has changed.

Here’s what I ended up having to do (TextMate 2.0-beta.6 on OS X Yosemite):

  • Open System Preferences / Keyboard
  • Select ‘Shortcuts’ tab
  • Select ‘App Shortcuts’ in the list on the left
  • Add an entry for TextMate
  • Populate it like so:

Screen Shot 2014-12-15 at 5.16.38 PM

And now, viola! Ctrl+Tab advances to the next tab, and Ctrl+Shift+Tab goes to the previous tab—just like in my web browser!

bashrc vs bash_profile

On the subject of bashrc

I’ve always been confounded by the presence of both .bashrc and .bash_profile and how they related.

It turns out to be simple, but 0% intuitive:

  • .bashrc is invoked for non-login, interactive shells
  • .bash_profile is invoked for login shells

The difference is powerful, surely, but also annoying. Most of the time, you just want something to always run in bash, and you don’t care about login vs. non-login.

Which is why it’s recommended to have .bash_profile merely source .bashrc.